public static class ExampleButton extends JPanel implements ActionListener { private JLabel output; private JButton b1, b2, b3;// notice we moved the JButton private int counter;// declaration here so that public ExampleButton() {// they are within the scope of counter=0;// actionPerformed output=new JLabel( +counter); b1=new JButton( increment ); b2=new JButton( decrement ); b3=new JButton( reset ); b1.addActionListener(this); b2.addActionListener(this); b3.addActionListener(this); JPanel p1=new JPanel(); p1.add(b1);p1.add(b2);p1.add(b3); setLayout(new GridLayout(2,1)); add(p1); add(output); } public void actionPerformed(ActionEvent e){ if(e.getSource()==b1) counter++; else if(e.getSource()==b2) counter--; else if(e.getSource()==b3) counter=0; output.setText( +counter); }