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

class ThreeButtons extends JFrame implements ActionListener
{

  private JButton b1;
  private JButton b2;
  private JButton b3;
  
  private JPanel centerPanel;

  public ThreeButtons()
  {
    Container c = getContentPane();
    c.setLayout(new BorderLayout());

    centerPanel = new JPanel();

    c.add("Center",centerPanel);

    b1 = new JButton("Red");
    b2 = new JButton("Green");
    b3 = new JButton("Blue");

    JPanel bp = new JPanel();
    bp.add(b1);
    bp.add(b2);
    bp.add(b3);

    b1.addActionListener(this);
    b2.addActionListener(this);
    b3.addActionListener(this);

    c.add("South", bp);

    setSize(400,400);
    setVisible(true);
  }

  // Crap inheritance and handling multiple events.
  public void actionPerformed(ActionEvent e)
  {
    JButton b = (JButton)(e.getSource());

    if (b.equals(b1))
      centerPanel.setBackground(Color.RED);

    if (b.equals(b2))
      centerPanel.setBackground(Color.GREEN);

    if (b.equals(b3))
      centerPanel.setBackground(Color.BLUE);
  }

  public static void main( String[] arg )
  {
    ThreeButtons app = new ThreeButtons();
    app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }

}


