/**
 * Material para as aulas 34 a 36 do Curso Técnico em Informática
 * do Colégio Estadual do Paraná
 * Prof. André Aparecido da Silva 
 * Disponível no site http://www.oxnar.com.br/2017/3ati
 */
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;

public class OxnarExercicioJList01a extends JFrame  implements ActionListener
{
		
		DefaultListModel 	Itens_da_Compras 	= new DefaultListModel();
		DefaultListModel 	Itens_de_Estoque 	= new DefaultListModel();
		JList 			 	Lista_Compras 		= new JList(Itens_da_Compras);
		JList 			 	Lista_Estoque 		= new JList(Itens_de_Estoque);
		JScrollPane		 	Painel_Rolante_Compras;
		JScrollPane		 	Painel_Rolante_Estoque;
		JPanel 				Painel_Norte, Painel_Leste, Painel_Oeste, Painel_Centro, Painel_Sul;
		JButton 			bt_Adicionar, bt_Excluir, bt_Fechar;
		JButton 			bt_ExcluirTudoCompras, bt_ExcluirTudo_Estoque; 

    	public OxnarExercicioJList01a() 
    	{
    			setLayout(new BorderLayout());
    			getContentPane().add("West", Painel_Oeste = new JPanel(new BorderLayout()));
				Painel_Oeste.add("North", new JLabel("COMPRAS"));
    			Lista_Compras.setVisibleRowCount(15);
    			JPanel Painel_Oeste2 = new JPanel(new BorderLayout());
    			Painel_Oeste.add("West", Painel_Oeste2);
    			Painel_Oeste2.add("Center", Painel_Rolante_Compras = new JScrollPane(Lista_Compras));	
    			Itens_da_Compras.addElement("MOUSE");
    			Itens_da_Compras.addElement("TECLADO");
    			Itens_da_Compras.addElement("GABINETE");
    			Itens_da_Compras.addElement("FONTE");
    			Itens_da_Compras.addElement("MONITOR");
    			Itens_da_Compras.addElement("PLACA MAE");
    			Itens_da_Compras.addElement("CABO HDMI");
    			Itens_da_Compras.addElement("CABO USB");
    			Itens_da_Compras.addElement("CABO VGA");
    			Itens_da_Compras.addElement("CABO DE ENERGIA");
    			Itens_da_Compras.addElement("IMPRESSORA");
    			Itens_da_Compras.addElement("SCANNER");
    			Itens_da_Compras.addElement("MEMORIA RAM");
    			Itens_da_Compras.addElement("PENDRIVE");
    			Itens_da_Compras.addElement("NOTEBOOK");
    			Itens_da_Compras.addElement("PLACA DE VÍDEO");
    			Itens_da_Compras.addElement("PLACA DE SOM");
    			Itens_da_Compras.addElement("PLACA DE REDE");
    			Itens_da_Compras.addElement("COLLER PARA PROCESSADOR 775");
    			Painel_Oeste2.add("South", bt_ExcluirTudoCompras = new JButton ("EXCLUIR TUDO"));
    			getContentPane().add("East", Painel_Leste = new JPanel (new BorderLayout()));
    			Painel_Leste.add("North", new JLabel("ESTOQUE"));
    			JPanel Painel_Leste2 = new JPanel(new BorderLayout());
    			Painel_Leste.add(Painel_Leste2);	
    			Painel_Leste2.add("Center", Painel_Rolante_Estoque = new JScrollPane(Lista_Estoque));	
    			Lista_Estoque.setVisibleRowCount(18);	
    			Itens_de_Estoque.addElement("BATERIA PARA NOTEBOOK");
    	        Itens_de_Estoque.addElement("COLLER PARA NOTEBOOK");
    	        Itens_de_Estoque.addElement("COLLER PARA PROCESSADOR 775");
    			Painel_Leste2.add("South",  bt_ExcluirTudo_Estoque = new JButton("EXCLUIR TUDO"));
    			getContentPane().add("South", Painel_Sul = new JPanel(new FlowLayout(FlowLayout.CENTER))); 		
    			Painel_Sul.add(bt_Adicionar		= new JButton("ADICIONAR"));
    			Painel_Sul.add(bt_Excluir		= new JButton("EXCLUIR"));
    			Painel_Sul.add(bt_Fechar		= new JButton("FECHAR"));
    			bt_Adicionar.addActionListener(this);
    			bt_Excluir.addActionListener(this);
    			bt_Fechar.addActionListener(this);
    			bt_ExcluirTudo_Estoque.addActionListener(this);
    			bt_ExcluirTudoCompras.addActionListener(this);	
    			setTitle("JList - EXERCICIO 01 DA AULA DE INTERFACES 08");
				setVisible(true);
				setSize(450, 400); 	
				setResizable(false);		

    	}
    	/////////////////////////////////////////
  
        ////////////////////////////////////////////////
    	public static void main (String args [])
    			{new OxnarExercicioJList01a();}
    	public void actionPerformed (ActionEvent e)
    	{
    			if(e.getSource()==bt_ExcluirTudo_Estoque)
    			{
    				Itens_de_Estoque.removeAllElements();
    			}	
    				
    				
    			if(e.getSource()==bt_ExcluirTudoCompras)
    			{
    				Itens_da_Compras.removeAllElements();
    			}    				
    			if(e.getSource()==bt_Adicionar)
    			{
    					Itens_de_Estoque.addElement(Lista_Compras.getSelectedValuesList());
    				
    			}	
    			if(e.getSource()==bt_Excluir)
    			{
    					if(Itens_de_Estoque.getSize()==0)
       					{
       						JOptionPane.showMessageDialog(null, "Sua lista esta vazia");
       					}	
       					else
       					{
       						Itens_de_Estoque.removeElementAt(Lista_Estoque.getSelectedIndex());
       						JOptionPane.showMessageDialog(null, "Item removido com sucesso");
       					}		
    			}	
    			if(e.getSource()==bt_Fechar)
    			{dispose();	}	   				
    	}        
}