import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class SimpleGUI2 extends JFrame implements ActionListener {
    
    private JButton purple, cyan, yellow;
    private Color purpColor = new Color(255, 0, 255), 
                  cyanColor = new Color(0, 255, 255),
                  yellColor = new Color(255, 255, 0);
    
    public SimpleGUI2() {
        setTitle("Simple GUI #2");
        getContentPane().setLayout(new FlowLayout());
        
        purple = new JButton("Purple");
        cyan = new JButton("Cyan");
        yellow = new JButton("Yellow");
        
        purple.addActionListener(this);
        cyan.addActionListener(this);
        yellow.addActionListener(this);
        
        getContentPane().add(purple);
        getContentPane().add(cyan);
        getContentPane().add(yellow);
        
        purple.setBackground(purpColor);
        cyan.setBackground(cyanColor);
        yellow.setBackground(yellColor);
    }
    
    public void actionPerformed(ActionEvent e) {
        Color c = new Color(255, 255, 255);
        
        if (e.getSource() == purple) {
            c = purpColor;
        } else if (e.getSource() == yellow) {
            c = yellColor;
        } else if (e.getSource() == cyan) {
            c = cyanColor;
        }
        
        getContentPane().setBackground(c);
    }
    
    public static void main(String[] args) {
        SimpleGUI2 sg = new SimpleGUI2();
        sg.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        sg.setSize(400, 300);
        sg.setVisible(true);    
    }
}
