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


public class Color_Buttons extends JFrame
{
    private JButton yellow, cyan, magenta;
    private JPanel jp;

    public Color_Buttons()
    //constructor
    {
	setTitle("Color Buttons");
	jp = new JPanel();
	Button_Handler bh = new Button_Handler();

	addWindowListener( new WindowHandler() );

	yellow = new JButton("Yellow");
	yellow.setBackground(Color.yellow);
	jp.add(yellow);
	yellow.addActionListener(bh);

	cyan = new JButton("cyan");
	cyan.setBackground(Color.cyan);
	jp.add(cyan);
	cyan.addActionListener(bh);

	magenta = new JButton("Magenta");
	magenta.setBackground(Color.magenta);
	jp.add(magenta);
	magenta.addActionListener(bh);
	
	getContentPane().add(jp);

    }


    class WindowHandler extends WindowAdapter
    {
	public void windowClosing( WindowEvent e )
	{ System.exit(0); }
    }

    class Button_Handler implements ActionListener
    {
	public void actionPerformed( ActionEvent evt )
	{
	    Object ob = evt.getSource();
	    if ( ob == yellow )
		jp.setBackground(Color.yellow);
	    else if ( ob == cyan )
		jp.setBackground(Color.cyan);
	    else if ( ob == magenta )
		jp.setBackground(Color.magenta);

	    jp.repaint();

	}
    }
    public static void main(String []args)
    {
	JFrame jf = new Color_Buttons();
	jf.setSize(300,300);
	jf.setVisible(true);
    }
}

