import java.awt.*;					//imports awt package
import javax.swing.*;  			//imports swing classes
import javax.swing.event.*;	//imports event packages from swing

public class ListPanel extends JPanel
{
	private JLabel label;  		//creates label
	private JList list;  				//creates list

	//Sets up a JPanel with a list

	public ListPanel()
	{
																//string array containing values of the list
		String[] colorNames = {"cyan", "magenta", "green", "yellow"};

		list = new JList(colorNames);								//creates new JList with string array of colors
		list.addListSelectionListener(new ListListener());  //adds action listener to list
																	//sets selection mode to the list  ( SINGLE_SELECTION )
		list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

		add(list);								//adds the JList to the panel

	}

															//private class that implements ListSelectionListener interface
	private class ListListener implements ListSelectionListener
	{														//method to do stuff depending on what the user selects
		public void valueChanged (ListSelectionEvent event)
		{													//String containing the selected value of the list
			String colorName = (String)list.getSelectedValue();

			if( colorName.equals("cyan"))  //if the selected color is cyan, set the background to cyan
			{
				setBackground(Color.cyan);
			}
			else if(colorName.equals("magenta")) //if the selected color is magenta, set the background to magenta
			{
				setBackground(Color.magenta);
			}
			else if(colorName.equals("green"))
			{
				setBackground(Color.green);
			}
			else if(colorName.equals("yellow"))
			{
				setBackground(Color.yellow);
			}
		}
	}
}