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

public class HiBye {
	public static void main(String [] args){
		JFrame frame=new JFrame("Hi Bye"); // Frame with title

			// Layout components in frame left to right, top to bottom
		frame.getContentPane().setLayout(new FlowLayout());

		JButton b1, b2; // Two reference to JButton, no buttons exist yet!!

		// Create the buttons
		b1=new JButton("Hi");
		b2=new JButton("Bye");

		// add them to the contentPane
		frame.getContentPane().add(b1);
		frame.getContentPane().add(b2);

		// Do the same with a JTextField
		JTextField t=new JTextField(10);
		frame.getContentPane().add(t);

		// Create button press event handlers
		MyButtonListener mb1=new MyButtonListener(t);
		MyButtonListener mb2=new MyButtonListener(t);

		// Tell the buttons who they should call when they are pressed
		b1.addActionListener(mb1);
		b2.addActionListener(mb2);
		
		// What happens when we close the JFrame...
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		// tell the frame to pack in all the components
		// this is done according to the layout manager
		frame.pack();

		// lets see the frame
		frame.setVisible(true);
		
	}
}

// implements...this requires that we provide certain specific methods 
// with specific signatures.

class MyButtonListener implements ActionListener {

	JTextField textField;
	MyButtonListener(JTextField t){ textField=t; }

	// 1) Modify this so that it prints out which button was pressed
	// 2) Modify this so that it sets the JTextField to which button was pressed

        // ActionListener requires that we implement the method below
        public void actionPerformed(ActionEvent e) {
                // System.out.println(" button pressed");
		// System.out.println(e.getActionCommand());
		textField.setText(e.getActionCommand());
        }
}
