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;

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

    Container c= this.getContentPane();
    c.add(this.b1, "Center");

    this.pack();
  }

  /** React to a button click: ask the user for the new button name. */
    // When you change what this method does, change the above
    // comment, too!
  public void actionPerformed(ActionEvent e) {
    JButton b= (JButton) e.getSource(); // this points to what b1 points to!
    // For your new code:
    //
    // The following line will have to go. You no longer want an
    // InputDialog - instead, you need to construct your own string
    // display.
    //
    String s= JOptionPane.showInputDialog("Enter new button text:");
    b.setText(s); // change the text of the button.
  }
}

