    01: import java.awt.*;
    02: import java.awt.event.*;
    03: import javax.swing.*;
    04:
    05: public class ActionTester
    06: {
    07:    public static void main(String[] args)
    08:    {
    09:       JFrame frame = new JFrame();
    10:
    11:       final int FIELD_WIDTH = 20;
    12:       final JTextField textField = new JTextField(FIELD_WIDTH);
    13:       textField.setText("Click a button!");
    14:
    15:       JButton helloButton = new JButton("Say Hello");
    16:
    17:       helloButton.addActionListener(new
    18:          ActionListener()
    19:          {
    20:             public void actionPerformed(ActionEvent event)
    21:             {
    22:                textField.setText("Hello, World!");
    23:             }
    24:          });
    25:
    26:       JButton goodbyeButton = new JButton("Say Goodbye");
    27:
    28:       goodbyeButton.addActionListener(new
    29:          ActionListener()
    30:          {
    31:             public void actionPerformed(ActionEvent event)
    32:             {
    33:                textField.setText("Goodbye, World!");
    34:             }
    35:          });
    36:
    37:       frame.setLayout(new FlowLayout());
    38:
    39:       frame.add(helloButton);
    40:       frame.add(goodbyeButton);
    41:       frame.add(textField);
    42:
    43:       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    44:       frame.pack();
    45:       frame.setVisible(true);
    46:    }
    47: }