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

public class SwingExample extends JFrame
{
    private static String labelPrefix = "Number of clicks: ";
    private int numClicks = 0;
    JLabel label = null;
    JButton button = null;

    public SwingExample()
    {
        label = new JLabel(labelPrefix + "0    ");
        button = new JButton("Click me!");
        button.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {   numClicks++;
                label.setText(labelPrefix + numClicks);
            }
        });
        Container panel = getContentPane();
        panel.setLayout(new GridLayout(2, 1));
        panel.add(button);
        panel.add(label);
        addWindowListener(new WindowAdapter()
        {
            public void windowClosing(WindowEvent e)
            {   System.exit(0);
            }
        });
        pack();
        setVisible(true);
    }

    public static void main(String[] args)
    {
        SwingExample app = new SwingExample();
    }
}
