import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class colorchange extends JPanel implements ActionListener{
static JFrame frame1;
JButton b1;
JButton b2;
JButton b3;
b1=new JButton("Red");
b2=new JButton("Green");
b3=new JButton("Blue");
b1.setMnemonic('R');
b2.setMnemonic('G');
b3.setMnemonic('B');
b1.setToolTipText("Red");
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
add(b1);
add(b2);
add(b3);
b1.requestFocus();
}
public void actionPerformed(ActionEvent evt){
Object source=evt.getSource();
if(source==b1)
setBackground(Color.red);
else if(source==b2)
setBackground(Color.green);
else if(source==b3)
setBackground(Color.blue);
}
public static void main(String[] a){
frame1=new JFrame("Color Change");
colorchange c1=new colorchange();
frame1.getContentPane().add("Center",c1);
frame1.setSize(200,150);
frame1.addWindowListener(new WindowAdapter(){
public void WindoClosing(WindowEvent e){
System.exit(0);
}
});
frame1.setVisible(true);
}
}