/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package windowtest; import java.awt.*; import java.awt.event.*; import javax.swing.*; /** * * @author jcmt */ public class PushCounterPanel extends JPanel { private int count; private JButton push; private JLabel label; public PushCounterPanel() { this.count = 0; this.push = new JButton("Push Me!"); push.addActionListener(new ButtonListener()); this.label = new JLabel("Pushes: "+ count); add(push); add(label); setBackground(Color.cyan); } private class ButtonListener implements ActionListener { public void actionPerformed(ActionEvent event) { count++; label.setText("Pushes: " + count); } } }