import javax.swing.JButton;
import javax.swing.JFrame;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class MyFrame extends JFrame implements ActionListener
{
    public static final int SAME = 0;
    private JButton aButton1;
    private JButton aButton2;   

    public MyFrame(JButton b1, JButton b2)
    {
        setSize(640,480);
        setLayout(null);
        aButton1 = b1;
        aButton2 = b2;
        add(aButton1);
        add(aButton2);
        setVisible(true);
        aButton1.addActionListener(this);
        aButton2.addActionListener(this);
    }

    public void actionPerformed (ActionEvent e)
    {
        JButton pressedButton = (JButton) e.getSource();
        JButton otherButton = null;
        String text = pressedButton.getActionCommand();

        if (text.compareToIgnoreCase(Driver.B1_NAME) == SAME)
        {
            otherButton = aButton2;
        }
        else if (text.compareToIgnoreCase(Driver.B2_NAME) == SAME)
        {
            otherButton = aButton1;
        }
        else
        {
            System.out.println("No match");
        }
        // One button's press event affects another control (button)
        // e.g. button1 pressed: this button laughs
        // button2 is 'jealous'
        otherButton.setText("NOT FAIR YOU PRESSED THE OTHER!");
        pressedButton.setText("HA! HA! HA!");


    }
}
