//TestButtonColor.java

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

public class TestButtonColor extends JFrame
{
    TestButtonColor(String s)
    {
        super(s);
    }

    public static void main(String[] args)
    {
        TestButtonColor app = new TestButtonColor("Testing Button Color");
        app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        app.getContentPane().setLayout(null);
        app.getContentPane().setBackground(Color.white);

        final JButton button = new JButton();
        button.setBackground(Color.red);
        button.setBounds(20, 20, 80, 40);
        app.getContentPane().add(button);
/*
        final JLabel label = new JLabel("Hello!", SwingConstants.CENTER);
        label.setOpaque(true);
        label.setBackground(Color.red);
        label.setBounds(120, 20, 50, 40);
        app.getContentPane().add(label);
*/
        button.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                /*if (label.getBackground().equals(Color.red))
                    label.setBackground(Color.green);
                else if (label.getBackground().equals(Color.green))
                    label.setBackground(Color.blue);
                else if (label.getBackground().equals(Color.blue))
                    label.setBackground(Color.red);*/
                if (e.getSource() == button && button.getBackground().equals(Color.red))
                    button.setBackground(Color.green);
                else if (e.getSource() == button && button.getBackground().equals(Color.green))
                    button.setBackground(Color.blue);
                else if (e.getSource() == button && button.getBackground().equals(Color.blue))
                    button.setBackground(Color.red);
            }
        });
        app.setBounds(50, 100, 200, 100);
        app.setVisible(true);
    }
}

