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

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

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

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

  /** The click count. */
  private int clickCount= 0;

  /** Create one button in the center. */
  public ButtonTAJFrame() {
    b1= new JButton("Click count: 0");
    b1.addActionListener(this);

    ta= new JTextArea("Click count: 0", 20, 30);

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

    this.pack();
  }

  /** React to a button click: ask the user for the new button name. */
  public void actionPerformed(ActionEvent e) {
    ++clickCount;

    JButton b= (JButton) e.getSource(); // this points to what b1 points to!
    b.setText("Click count: " + clickCount);

	// Set the text of the text area to whatever it had, plus a newline,
	// plus the text on the button.
    ta.setText(ta.getText() + "\n" + b.getText());

  }
}
