    01: import java.awt.*;
    02: import java.awt.event.*;
    03: import javax.swing.*;
    04:
    05: public class ActionTest
    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:
    27:       JButton goodbyeButton = new JButton("Say Goodbye");
    28:
    29:       goodbyeButton.addActionListener(new
    30:          ActionListener()
    31:          {
    32:             public void actionPerformed(ActionEvent event)
    33:             {
    34:                textField.setText("Goodbye, World!");
    35:             }
    36:          });
    37:
    38:       Container contentPane = frame.getContentPane();
    39:       contentPane.setLayout(new FlowLayout());
    40:
    41:       contentPane.add(helloButton);
    42:       contentPane.add(goodbyeButton);
    43:       contentPane.add(textField);
    44:
    45:       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    46:       frame.pack();
    47:       frame.show();
    48:    }
    49: }