Professional Documents
Culture Documents
Import Javax
Import Javax
*;
class Stack
int top=-1;
int size=0;
int[] arr;
this.size=size;
arr[++top] = value;
return arr[top--];
top=-1;
}
}
public STACKGUI() {
initComponents();
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
*/
@SuppressWarnings("unchecked")
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
masuk.setText("MASUK");
masuk.addActionListener(new java.awt.event.ActionListener() {
masukActionPerformed(evt);
});
hapus.setText("HAPUS");
hapus.addActionListener(new java.awt.event.ActionListener() {
hapusActionPerformed(evt);
});
perbahrui.setText("PERBAHRUI");
perbahrui.addActionListener(new java.awt.event.ActionListener() {
perbahruiActionPerformed(evt);
});
jLabel1.setText("STACK (TUMPUKAN)");
arr3.addActionListener(new java.awt.event.ActionListener() {
arr3ActionPerformed(evt);
});
arr5.addActionListener(new java.awt.event.ActionListener() {
arr5ActionPerformed(evt);
});
jLabel4.setText("KEDUA");
jLabel5.setText("KETIGA");
jLabel6.setText("KEEMPAT");
jLabel7.setText("TERAKHIR");
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(masuk)
.addComponent(hapus)
.addGap(18, 18, 18)
.addComponent(perbahrui))
.addContainerGap(22, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING,
false)
.addComponent(arr1, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(arr2, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(arr3, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(arr4, javax.swing.GroupLayout.Alignment.LEADING))
.addComponent(jLabel1)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel2)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(masuk)
.addComponent(masuktxt, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(hapus)
.addComponent(perbahrui))
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(arr1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel7))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(arr2, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel6))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(arr3, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(arr4, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(arr5, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3))
.addContainerGap(33, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
}
private void arr5ActionPerformed(java.awt.event.ActionEvent evt) {
stackx.push(Integer.parseInt(masuktxt.getText()));
switch(stackx.top){
case 0:
arr5.setText(masuktxt.getText());
break;
case 1:
arr4.setText(masuktxt.getText());
break;
case 2:
arr3.setText(masuktxt.getText());
break;
case 3:
arr2.setText(masuktxt.getText());
break;
case 4:
arr1.setText(masuktxt.getText());
JOptionPane.showMessageDialog(null,"full");
break;
switch(stackx.top){
case 0:
arr5.setText("");
break;
case 1:
arr4.setText("");
break;
case 2:
arr3.setText("");
break;
case 3:
arr2.setText("");
break;
case 4:
arr1.setText("");
break;
stackx.pop();
}
private void perbahruiActionPerformed(java.awt.event.ActionEvent evt) {
switch(0){
case 0:
arr5.setText("");
case 1:
arr4.setText("");
case 2:
arr3.setText("");
case 3:
arr2.setText("");
case 4:
arr1.setText("");
/**
*/
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
*/
try {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
java.util.logging.Logger.getLogger(STACKGUI.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
java.util.logging.Logger.getLogger(STACKGUI.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
java.util.logging.Logger.getLogger(STACKGUI.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
java.util.logging.Logger.getLogger(STACKGUI.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
new STACKGUI().setVisible(true);
});
}
Import javax.swing.*;
Public Stack{
Int size=0;
Int [] arr;