import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;

public class Exemplo_JComboBoxCor extends JFrame implements ActionListener, ItemListener
{
	    JComboBox Combo = new JComboBox();
	    public Exemplo_JComboBoxCor()
    	{
    			setLayout(new FlowLayout());
    			add(new JLabel("SELECIONE UMA COR"));
    			add(Combo);
    			Combo.addItem("BRANCO - DEFAULT");
    			Combo.addItem("AZUL");
    			Combo.addItem("VERDE");
    			Combo.addItem("AMARE");
    			Combo.addItem("PRETO");
    			Combo.addItem("LARANJA");
    			Combo.addItem("CYAN");
    			Combo.addItem("MARRON");

				Combo.addItemListener(this);
    			setTitle("OXNAR - AULA SOBRE JCOMBOBOX COM CORES");
    			setSize(400, 400);
    			setLocationRelativeTo(null);
    			setVisible(true);

		}
		public void actionPerformed (ActionEvent e)
		{

		}
		public static void main (String args [])
		{
     				new Exemplo_JComboBoxCor();
		}
		public void itemStateChanged( ItemEvent e )
	    {

				String resposta;
 				if (e.getStateChange() == ItemEvent.SELECTED)
				{
               			//pegando o texto do item selecionado
               			resposta = e.getItem().toString();

						if ( resposta.equals("VERDE"))
								{getContentPane().setBackground(Color.green);}


						if ( resposta.equals("LARANJA"))
								{getContentPane().setBackground(Color.orange);}
						if ( resposta.equals("PRETO"))
								{getContentPane().setBackground(Color.black);}
						if ( resposta.equals("AMARELO"))
								{getContentPane().setBackground(Color.yellow);}
						if ( resposta.equals("AZUL"))
								{getContentPane().setBackground(Color.blue);}
						if ( resposta.equals("CYAN"))
								{getContentPane().setBackground(Color.cyan);}

						if ( resposta.equals("SELECIONE..."))
								{getContentPane().setBackground(Color.white);}
				}
		}
}