import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ItemEvent;  
import java.awt.event.ItemListener;  

public  class OxnarExemploJComboBox extends JFrame implements ActionListener, ItemListener 
{

		JComboBox <String> Minha_Combo = new JComboBox<String>();
		JPanel Painel_Norte, Painel_Centro, Painel_Sul, Painel_Sul1, Painel_Sul2;
		JTextField tf_NovoItem; 
		JButton bt_Adicionar, bt_Excluir, bt_ExcluirTudo, bt_Sair;
		
       
       	public OxnarExemploJComboBox()
       	{
    			getContentPane().setLayout(new BorderLayout());
    			getContentPane().add("North", Painel_Norte   = new JPanel (new FlowLayout(FlowLayout.CENTER)));
    			Painel_Norte.add(new JLabel("EXEMPLO JComboBox"));
    			getContentPane().add("Center", Painel_Centro = new JPanel (new FlowLayout(FlowLayout.CENTER)));
    			Painel_Centro.add(Minha_Combo);
    			Minha_Combo.addItem("SELECIONE UMA CIDADE");
    			
    			getContentPane().add("South", Painel_Sul = new JPanel (new GridLayout(2, 1)));
    			Painel_Sul.add(Painel_Sul1 = new JPanel (new FlowLayout(FlowLayout.CENTER)));
    			Painel_Sul1.add(new JLabel("NOVO ITEM:"));
    			Painel_Sul1.add(tf_NovoItem = new JTextField(15));
    			Painel_Sul.add(Painel_Sul2 = new JPanel (new FlowLayout(FlowLayout.CENTER)));
				Painel_Sul2.add(bt_Adicionar = new JButton("ADICIONAR CIDADE"));
				
				Painel_Sul2.add(bt_Excluir     = new JButton("EXCLUIR CIDADE"));
				
				Painel_Sul2.add(bt_ExcluirTudo = new JButton("EXCLUIR TUDO"));
				Painel_Sul2.add(bt_Sair        = new JButton("SAIR DO SISTEMA")); 				
 				setDefaultCloseOperation(EXIT_ON_CLOSE);
 				setTitle("OXNAR: Exemplo JList");
               	//pack();
               	setSize(500, 500);
				setVisible(true);
				//Eventos de Botões
				bt_Adicionar.addActionListener(this);
				bt_Excluir.addActionListener(this);
				bt_ExcluirTudo.addActionListener(this);
				bt_Sair.addActionListener(this);
				//Eventos de JCombo
				Minha_Combo.addItemListener(this);
       	}

       	public void actionPerformed(ActionEvent e) 
       	{
       		
				if(e.getSource()==bt_Adicionar)
				{
						Minha_Combo.addItem(tf_NovoItem.getText().toUpperCase());
						tf_NovoItem.setText("");
						
				}
				if(e.getSource()==bt_Excluir)
				{
						Minha_Combo.removeItem(Minha_Combo.getSelectedItem());
				}	
				if(e.getSource()==bt_ExcluirTudo)
				{
						Minha_Combo.removeAllItems();
						Minha_Combo.addItem("SELECIONE UMA CIDADE");
				}	
				if(e.getSource()==bt_Sair)
				{						
					System.exit(0);
				}	       	
		}
        public void itemStateChanged(ItemEvent e)	
       	{
	
              
       	}
       	public static void main (String args [])
       	{
       		new OxnarExemploJComboBox();
       	}	
}