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


public class Oxnar_Exemplo_JComboBox extends JFrame implements ActionListener, ItemListener
{
	JComboBox cbb_Cores = new JComboBox();
	JComboBox cbb_Sexo = new JComboBox();

	public Oxnar_Exemplo_JComboBox ()
	{
		getContentPane().setLayout(new GridLayout(6, 2));
		getContentPane().add(new JLabel("CORES:"));
		getContentPane().add(cbb_Cores);
		cbb_Cores.addItem("SELECIONE...");
		cbb_Cores.addItem("AMARELO");
		cbb_Cores.addItem("AZUL");
		getContentPane().add(new JLabel("2"));
		getContentPane().add(new JLabel("4"));

		getContentPane().add(new JLabel("SEXO"));
		getContentPane().add(cbb_Sexo);
		cbb_Sexo.addItem("MASCULINO");
		cbb_Sexo.addItem("FEMININO");
		cbb_Sexo.addItem("NÃO INFORMADO");

		getContentPane().add(new JLabel("5"));
		getContentPane().add(new JLabel("6"));
		getContentPane().add(new JLabel("7"));
		getContentPane().add(new JLabel("8"));

		getContentPane().setBackground(Color.cyan);
		setSize(500, 400);
		setVisible(true);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		cbb_Cores.addItemListener(this);
		cbb_Sexo.addItemListener(this);
		cbb_Cores.addActionListener(this);

	}
	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("AMARELO"))
				{
						getContentPane().setBackground(Color.yellow);
				}
				if ( resposta.equals("AZUL"))
				{
						getContentPane().setBackground(Color.blue);
				}
				if ( resposta.equals("SELECIONE..."))
				{
						getContentPane().setBackground(Color.white);
				}
				resposta = e.getItem().toString();
   				if ( resposta.equals("MASCULINO"))
						{System.out.println("OPÇÃO SELECIONADA: MASCULINO");}
				if ( resposta.equals("FEMININO"))
						{System.out.println("OPÇÃO SELECIONADA: FEMININO");}
				if ( resposta.equals("NÃO INFORMADO"))
						{System.out.println("OPÇÃO SELECIONADA: INDEFINIDO");}
		}
	}
	public static void main (String args [])
	{
		new Oxnar_Exemplo_JComboBox();
	}
	public void actionPerformed (ActionEvent e)
	{

		/*if(resposta.equals("1"))
			getContentPane().setBackground(Color.yellow);
		if(resposta.equals("2"))
			getContentPane().setBackground(Color.blue);
		if(resposta.equals("0"))
			getContentPane().setBackground(Color.white);
			/*getContentPane().setBackground(Color.yellow);
			getContentPane().setBackground(Color.yellow);
			getContentPane().setBackground(Color.yellow);
			getContentPane().setBackground(Color.yellow);
			*/

	}
}

