import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ButtonFrame extends JFrame implements ActionListener{
private static final long serialVersionUID = 1L;
private JPanel buttonPanel;
private static final int DEFAULT_WIDTH = 300;
private static final int DEFAULT_HEIGHT = 200;
JButton yellowButton ,blueButton,redButton;
public ButtonFrame()
{
setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
yellowButton = new JButton("Yellow");
blueButton = new JButton("Blue");
redButton = new JButton("Red");
buttonPanel = new JPanel();
buttonPanel.add(yellowButton);
buttonPanel.add(blueButton);
buttonPanel.add(redButton);
add(buttonPanel);
yellowButton.addActionListener(this);
blueButton.addActionListener(this);
redButton.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==yellowButton)
buttonPanel.setBackground(Color.YELLOW);
if(e.getSource()==blueButton)
buttonPanel.setBackground(Color.BLUE);
if(e.getSource()==redButton)
buttonPanel.setBackground(Color.RED);
}
}