//creates the windows and dialogue box which will perform the jcolorchooser action
//code tutorial by http://www.youtube.com/user/thenewboston

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class Chooser extends JFrame{
	
	private JButton b;
	private Color color = (Color.WHITE);	//sets default color to white
	private JPanel panel;

	//builds constructor
	public Chooser(){
		super("The Title");
		panel = new JPanel();		//creates the new panel
		panel.setBackground(color);	//color already valued as WHITE so bg will be white
		
		//builds button
		b = new JButton("Choose a color");
		b.addActionListener(
					//"anonymous inner class"
					/*ÒÉ an unnamed class declared entirely within the body of
					 * another class or interface.Ó
					*/
				new ActionListener(){
					public void actionPerformed(ActionEvent event){
						//implements the JColorchooser
						//(position-center if null, dialog title, sets auto color (it is default here)
						color = JColorChooser.showDialog(null, "Pick a color", color);
						//in case no color is selected
						if(color==null)
							color=(Color.WHITE);
						
						//changes background color accordingly
						panel.setBackground(color);
						
					}
				}
			);
		
		
		//adds everything to the screen
		add(panel, BorderLayout.CENTER);	//panel appears at center of screen
		add(b, BorderLayout.SOUTH);			//button appears at bottom of screen
		setSize(425,150);					//panel size
		setVisible(true);
	}
}




