1  import java.awt.event.ActionListener;
  2  import javax.swing.JButton;
  3  import javax.swing.JFrame;
  4  
  5  /**
  6     This program demonstrates how to install an action listener.
  7  */
  8  public class ButtonViewer
  9  {  
 10     private static final int FRAME_WIDTH = 100;
 11     private static final int FRAME_HEIGHT = 60;
 12  
 13     public static void main(String[] args)
 14     {  
 15        JFrame frame = new JFrame();
 16        JButton button = new JButton("Click me!");
 17        frame.add(button);
 18       
 19        ActionListener listener = new ClickListener();
 20        button.addActionListener(listener);
 21  
 22        frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
 23        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 24        frame.setVisible(true);
 25     }
 26  }