//  JColorChooserDemo.java - Using the Java Color Chooser Dialog

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class JColorChooserDemo extends JFrame {

    public JColorChooserDemo() {
        contentPane = getContentPane();
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        contentPane.setBackground(bgColor);
        contentPane.setLayout(new BorderLayout());
        setTitle("JColorChooser Demo");
        setBounds(XY, XY, WIDTH, HEIGHT);
        JPanel buttonPanel = new JPanel();
        buttonPanel.setBackground(Color.WHITE);
        buttonPanel.setLayout(new FlowLayout());
        JButton chooseButton = new JButton(sButtonLabel);
        chooseButton.addActionListener(new Handler(this));
        buttonPanel.add(chooseButton);
        contentPane.add(buttonPanel, BorderLayout.SOUTH);
    }

    public static void main(String[] args) {
        JColorChooserDemo gui = new JColorChooserDemo();
        gui.setVisible(true);
    }

    public static final int XY     = 200;
    public static final int WIDTH  = 400;
    public static final int HEIGHT = 200;
    private Container contentPane;
    private Color bgColor = Color.LIGHT_GRAY;
    private String sButtonLabel = "Choose a Color";

    private class Handler implements ActionListener {

        private Handler(JFrame jFrame) {
            this.jFrame = jFrame;
        }

        public void actionPerformed(ActionEvent e) {
            bgColor = JColorChooser.showDialog(jFrame, "JColorChooser", bgColor);
            contentPane.setBackground(bgColor);
        }

        private JFrame jFrame;

    }
    
}
