import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class FirstGUI2
{
  private int numClicks = 0;
  private JButton button;

  public Component createComponents()
    {
      button = new JButton(String.valueOf(numClicks));
      button.addActionListener(new ActionListener()
	{
	  public void actionPerformed(ActionEvent e)
	    {
	      numClicks++;
	      button.setText(String.valueOf(numClicks));
	    }
	});

      JPanel pane = new JPanel();
      pane.add(button);

      return pane;
    }

  public static void main(String[] args)
    {
      JFrame frame = new JFrame("Our First GUI");
      FirstGUI2 gui = new FirstGUI2();
      Component contentsPanel = gui.createComponents();
      frame.getContentPane().add(contentsPanel);

      // make the frame closeable
      frame.addWindowListener(new WindowAdapter()
	{
	  public void windowClosing(WindowEvent e)
	    {
	      System.exit(0);
	    }
	});

      // move frame and make it visible
      frame.setLocation(100, 100);
      frame.setSize(300, 100);
      frame.setVisible(true);
    }
}
