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

/**
 * A window with one button that changes text.
 */
public class ButtonJFrame extends JFrame implements ActionListener {


  /** My button. */
  private JButton b1;

  /** My text area. */
  private JTextArea text;

  /** Create one button in the center. */
  public ButtonJFrame() {
    b1 = new JButton("Click me");
    b1.addActionListener(this);

    Container c = this.getContentPane();
    c.add(this.b1, "South");
    
    this.pack();
  }

  /** React to a button click: ask the user for the new button name. */
  public void actionPerformed(ActionEvent e) {
    JButton b = (JButton) e.getSource(); // This makes b point to the b1 button!
    String s = JOptionPane.showInputDialog("Enter new button text:");
    b.setText(s); // change the text of the button.
  }
}

