import java.awt.*;
import javax.swing.*;
import java.awt.event.*; 

public class ButtonTest extends JFrame implements ActionListener {
    private JLabel countLabel;
    private JButton button;
    private int count = 0; 
    private Container contentPane;
    public ButtonTest() {
	contentPane = getContentPane();
	contentPane.setLayout(new GridLayout(2,1));
	// change the count to string. alignment is center
	countLabel = new JLabel(Integer.toString(count), JLabel.CENTER);
	button = new JButton("Click me");
	contentPane.add(countLabel);
	contentPane.add(button);
	// the class is an action listener
	button.addActionListener(this);
    }
    
    // what happens after you click the button
    public void actionPerformed(ActionEvent e) {
	count++;
	countLabel.setText(Integer.toString(count));
    }
    
   public static void main(String[] args) {
        ButtonTest f = new ButtonTest();
	f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	f.pack();
	f.setVisible(true);
    }
}
	
	
