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

public class ButtonInFrame implements ActionListener {

  public JFrame frame;
  public JButton button;

  public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        createAndShowGUI();
      }
    });
  } 

  public static void createAndShowGUI() {
    ButtonInFrame bif = new ButtonInFrame(); 
    bif.frame.pack();
    bif.frame.setVisible(true); 
  }

  public ButtonInFrame() {
    frame = new JFrame();
    button = new JButton("Click Me");
    button.addActionListener(this);
    frame.add(button);
  }

  public void actionPerformed(ActionEvent event) {
    Component c = (Component)event.getSource();
    if (c == button) {
      System.out.println("Button clicked");
    }
  }
}

