Can anyone help me use a JLabel to display a stack??? I've been searching java.sun.com and I can't seem to find the right way to do it. I get errors every time. I think everything is right in my program besides this. Thanks for looking. Here's what I have:
(Am I posting the code right?)
public class GraphicStackPanel extends JPanel {
private JLabel inputLabel, outputLabel, resultLabel;
private JTextField pushstring;
private JButton push, pop;
int count = 0;
public GraphicStackPanel(){
inputLabel = new JLabel ("Enter word here: ");
pushstring = new JTextField (10);
push = new JButton ("Push!");
push.addActionListener (new ButtonListener());
outputLabel = new JLabel ("Your Stack: ");
resultLabel = new JLabel ("--");
pop = new JButton ("Pop!");
pop.addActionListener (new ButtonListener());
add(inputLabel);
add(pushstring);
add(push);
add(pop);
add(outputLabel);
add(resultLabel);
setPreferredSize (new Dimension (400, 300));
setBackground (Color.white);
}
private class ButtonListener implements ActionListener{
Stack stack = new Stack();
public void actionPerformed (ActionEvent event){
if (event.getSource() == push){
stack.push (pushstring);
resultLabel.setText(stack);
}
else{
stack.pop ();
resultLabel.setText(stack);
}
}
}
}