rendered paste bodyimport java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class PushCounterPanel extends JPanel
{
private int count;
private JButton push1;
private JButton push2;
private JLabel label;
/////////////////////this is what was missing from the code. clickMe wasnt initialized.there was also a hanging semi colon somewhere
private boolean _clickMeMode = true;
//contstructor: sets up the GUI.
public PushCounterPanel()
{
count=0;
push1=new JButton ("increase");
push1.addActionListener (new ButtonListener());
push2=new JButton ("decrease");
push2.addActionListener (new ButtonListener());
label=new JLabel ("count: " +count);
add (push1);
add (push2);
add (label);
setPreferredSize (new Dimension(300, 40));
setBackground (Color.green);
}
//represents a listener for button push (action) events.
private class ButtonListener implements ActionListener
{
//updates the couter and label when the button is pushed.
public void actionPerformed (ActionEvent event)
{
Object source = event.getSource();
if (_clickMeMode == true) {
push1.setText("count: "+ count++);
label.setText("count: " + count);
} else {
push2.setText("count: "+ count--);
label.setText("count: " + count);
_clickMeMode = false;
}
}
}
}