001package horstmann.ch04_action1;
002import java.awt.FlowLayout;
003import javax.swing.JButton;
004import javax.swing.JFrame;
005import javax.swing.JTextField;
006
007public class ActionTester
008{
009        public static void main(String[] args)
010        {
011                JFrame frame = new JFrame();
012
013                final int FIELD_WIDTH = 20;
014                final JTextField textField = new JTextField(FIELD_WIDTH);
015                textField.setText("Click a button!");
016
017                JButton helloButton = new JButton("Say Hello");
018
019                helloButton.addActionListener(event -> textField.setText("Hello, World!"));
020
021                JButton goodbyeButton = new JButton("Say Goodbye");
022
023                goodbyeButton.addActionListener(event -> textField.setText("Goodbye, World!"));
024
025                frame.setLayout(new FlowLayout());
026
027                frame.add(helloButton);
028                frame.add(goodbyeButton);
029                frame.add(textField);
030
031                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
032                frame.pack();
033                frame.setVisible(true);
034        }
035}