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

/**
 * ColorSelect will demonstrate how to use slider buttons to make
 *  a color mixer that has some beauty, but not enough.
 * 
 * 
 * @author Kathryn McKinley
 * @version April 2007
 * 
 * NOTES: To make the implements ChangeListner work you need to 
 *       import javax.swing.event.*;
 * and to define a method that implements the interface:
 *        public void stateChanged(ChangeEvent e)
 *        
 * 1) Show basics
 * 2) Add tick marks to the slider bars
 * 3) Discuss limitation of GridLayout here, and if time solve it with
 *    additional containers
 */

public class ColorSelect implements ChangeListener{

    // specifies how to layout the parts of the GUI
    // Grid forces all the elements to be the same size
    private static final GridLayout LAYOUT_STYLE = new GridLayout(7,1);
        
    // Make a window with a title - just one ever
    private JFrame window = new JFrame("Color Mixer");
    
    // Make a painting area to put color in
    private JPanel colorBox = new JPanel();
    
    // Sliders - user selects value in the range of 0 to 100, initial value 0
    // JSlider( int min, int max, int initialValue);
    private JSlider redSlider   = new JSlider(0, 100, 0);
    private JSlider greenSlider = new JSlider(0, 100, 0);
    private JSlider blueSlider  = new JSlider(0, 100, 0);
    
    private JLabel redLabel   = new JLabel ("Red", JLabel.CENTER);
    private JLabel greenLabel = new JLabel ("Green", JLabel.CENTER);     
    private JLabel blueLabel  = new JLabel ("Blue", JLabel.CENTER);
    /**
     * Constructor for objects of class QuestionGUI
     *    configures the GUI
     */
    public ColorSelect()
    {
        // register the listner
        redSlider.addChangeListener(this);
        blueSlider.addChangeListener(this);
        greenSlider.addChangeListener(this);

        // window size and exit 
        // window.setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
        window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         
        // arrange compoents in GUI
        window.setLayout(LAYOUT_STYLE);
        colorBox.setBackground(new Color(0.01F * redSlider.getValue(), 0.01F *greenSlider.getValue(), 0.01F * blueSlider.getValue())); 
        window.add(colorBox);
/*
        redSlider.createStandardLabels(10);
        redSlider.setPaintLabels(true);
        redSlider.setMajorTickSpacing(10);
        redSlider.setPaintTicks(true);
*/
        window.add(redSlider);    
        window.add(redLabel);
        
        window.add(greenSlider);    
        window.add(greenLabel);
        
        window.add(blueSlider);
        window.add(blueLabel);
        
        window.pack();
        window.setVisible(true);
    }
    
    /**
     * This handler is for elements that change, and how to react to them
     * 
     * @param  user event
     */
    public void stateChanged(ChangeEvent e)
    {  
        // Use the response according to the button selection
        float redValue   = 0.01F * redSlider.getValue();
        float greenValue = 0.01F * greenSlider.getValue();
        float blueValue  = 0.01F * blueSlider.getValue();
        
        colorBox.setBackground(new Color(redValue, greenValue, blueValue));
        
        System.out.println(colorBox.getSize());
    }
    public static void main(String[] args) {
        ColorSelect colorSelector = new ColorSelect();   
    }
}
