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

class SimpleGUI extends JPanel implements ActionListener {
	JTextField tf;
	public SimpleGUI(){
		// Method of JComponent
		setBackground(Color.white);
		setMinimumSize(new Dimension(100,100));

		// Create 4 buttons. What is in quotes appears on the button
		JButton b1=new JButton("Bill");
		JButton b2=new JButton("Bob");
		JButton b3=new JButton("George");
		JButton b4=new JButton("Fred");
		tf=new JTextField(10);
		
		// 1. SET ACTION COMMAND
		// This command sets the text string that can be accessed
		// by the action event (see 2.)
		b1.setActionCommand("Hi Bill");
		b2.setActionCommand("Hello Bob");
		b3.setActionCommand("Nice day George");
		b4.setActionCommand("Right, said Fred");
		
		// Adds the buttons to the pane
		add(b1); 
		add(b2);
		add(b3);
		add(b4);
		add(tf);
		
		// Sets an action listener for each button
		b1.addActionListener(this);
		b2.addActionListener(this);
		b3.addActionListener(this);
		b4.addActionListener(this);
	}

	public void actionPerformed(ActionEvent e){
		// 2. GET ACTION COMMAND
		// e is the name of the action event
		// Using e you can access the Action Command that we set
		// earlier (see 1).
		
		// Prints the action command to the screen.
		System.out.println(e.getActionCommand());
		
		// Puts the action command in the text field.
		tf.setText(e.getActionCommand());
	}
}
