package horstmann.ch04_action1;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;

public class ActionTester
{
	public static void main(String[] args)
	{
		JFrame frame = new JFrame();

		final int FIELD_WIDTH = 20;
		final JTextField textField = new JTextField(FIELD_WIDTH);
		textField.setText("Click a button!");

		JButton helloButton = new JButton("Say Hello");

		helloButton.addActionListener(event -> textField.setText("Hello, World!"));

		JButton goodbyeButton = new JButton("Say Goodbye");

		goodbyeButton.addActionListener(event -> textField.setText("Goodbye, World!"));

		frame.setLayout(new FlowLayout());

		frame.add(helloButton);
		frame.add(goodbyeButton);
		frame.add(textField);

		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.pack();
		frame.setVisible(true);
	}
}
