/**
 * @version 1.00 2017/5/10
 */
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;




public class JFrameCalculadora extends JFrame implements ActionListener
{
    	String Equacao="";

		JButton bt_Somar, bt_Subtrair, bt_Dividir, bt_Multiplicar;
		JButton bt_CE;
		JButton bt_0, bt_1, bt_2, bt_3, bt_4, bt_5, bt_6, bt_7, bt_8, bt_9;
		JButton bt_Ponto, bt_Igual, bt_Fatorial, bt_MaisMenos, bt_Mod, bt_Potencia;
		JButton bt_Porcentagem;
		JTextField tf_Visor;
		JLabel lbl_Visor;
		JPanel Painel_Norte, Painel_Norte1, Painel_Norte2;
		JPanel Painel_Botoes;
		JPanel Painel_Operacoes;
		private  JPopupMenu Menu_PopUp = new JPopupMenu("MENU SUSPENSO");
		JMenuItem MenuItem_Copiar, MenuItem_Colar, MenuItem_Sair;
		
    	public JFrameCalculadora() 
    	{
    			//PopupMeu
    			getContentPane().add(Menu_PopUp);
                Menu_PopUp.show();
    			Menu_PopUp.add(MenuItem_Copiar  = new JMenuItem("COPIAR"));
    			
    			Menu_PopUp.add(MenuItem_Colar   = new JMenuItem("COLAR"));
    			Menu_PopUp.add(MenuItem_Sair    = new JMenuItem("SAIR..."));
				
    			getContentPane().setLayout(new BorderLayout());
    			getContentPane().add("North", Painel_Norte = new JPanel(new GridLayout(3, 1)));
    			Painel_Norte.add(Painel_Norte1 = new JPanel(new FlowLayout(FlowLayout.LEFT)));
    			Painel_Norte1.add(new JLabel("VISOR:"));
    			Painel_Norte.add(Painel_Norte2 = new JPanel(new GridLayout(1, 1)));
    			Painel_Norte2.add(lbl_Visor = new JLabel ());
    			Painel_Norte2.setBackground(Color.orange);
    			lbl_Visor.setBackground(Color.orange);
    			lbl_Visor.setText("AGUARDANDO CÁLCULOS");
    			Painel_Norte.add(tf_Visor = new JTextField(20));
                
    			tf_Visor.setFont(new Font("serif", Font.PLAIN, 26));
    			getContentPane().add("Center", Painel_Botoes = new JPanel(new GridLayout(4,4)));
     			Painel_Botoes.add(bt_7 = new JButton("7"));
    			Painel_Botoes.add(bt_8 = new JButton("8"));
     			Painel_Botoes.add(bt_9 = new JButton("9"));
     			Painel_Botoes.add(bt_Dividir = new JButton ("/"));
    			Painel_Botoes.add(bt_4 = new JButton("4"));
     			Painel_Botoes.add(bt_5 = new JButton("5"));
    			Painel_Botoes.add(bt_6 = new JButton("6"));
    			Painel_Botoes.add(bt_Multiplicar = new JButton("*"));
     			Painel_Botoes.add(bt_1 = new JButton("1"));
    			Painel_Botoes.add(bt_2 = new JButton("2"));
     			Painel_Botoes.add(bt_3 = new JButton("3"));
    			Painel_Botoes.add(bt_Subtrair = new JButton("-"));
    			Painel_Botoes.add(bt_0 = new JButton("0"));
                Painel_Botoes.add(bt_Ponto = new JButton("."));
                Painel_Botoes.add(bt_Igual = new JButton("="));
   			    Painel_Botoes.add(bt_Somar = new JButton("+")); 
   			    getContentPane().add("East", Painel_Operacoes = new JPanel(new GridLayout(4, 2)));
   			    Painel_Operacoes.add(bt_CE        	= new JButton("CE"));	
   			    Painel_Operacoes.add(bt_Potencia  	= new JButton("x^y"));	

   			    Painel_Operacoes.add(bt_Fatorial  	= new JButton("x!"));
  	//		   Painel_Operacoes.add(bt_MaisMenos 	= new JButton("+/-"));~
//   			    Painel_Operacoes.add(bt_Porcentagem	- new JButton("%"));
   			    Painel_Operacoes.add(bt_Mod	        = new JButton("MOD"));			   			
    			setSize(350, 350);
    			//pack();
    			setVisible(true);
    			setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     			setTitle("OXNAR - CALCULADORA");
     			//Tornando os botões sensiveis ao click do mouse
     			bt_0.addActionListener(this);
     			bt_1.addActionListener(this);
     		    bt_2.addActionListener(this);
     		    bt_3.addActionListener(this);
     		    bt_4.addActionListener(this);
     		    bt_5.addActionListener(this);
     		    bt_6.addActionListener(this);
     		    bt_7.addActionListener(this);
     		    bt_8.addActionListener(this);
     		    bt_9.addActionListener(this);
     		    bt_CE.addActionListener(this);
   
    	}
    	private void formMouseReleased(java.awt.event.MouseEvent evt) 
    	{                                   
        		if(evt.isPopupTrigger())
        		{
            			 Menu_PopUp.show(this, evt.getX(), evt.getY());
            			
    	    	}
	    }                                  

    
    	public void actionPerformed (ActionEvent e)
    	{
					if(e.getSource()==bt_CE)
					{
						Equacao=""; //Limpa a variável equação;
						tf_Visor.setText("");
					}	
    				if((e.getSource()==bt_0)||(e.getSource()==bt_1)||(e.getSource()==bt_2)||(e.getSource()==bt_3)||(e.getSource()==bt_4)||(e.getSource()==bt_5)||(e.getSource()==bt_6)||(e.getSource()==bt_7)||(e.getSource()==bt_8)||(e.getSource()==bt_9))
    				{
    						Equacao=Equacao+e.getActionCommand().toString();
    						tf_Visor.setText(Equacao);
    						
    				}
    				lbl_Visor.setText(""+Equacao);//A variável equação ficará fora de todos os IF
    	}	
    	public static void main (String args [])
    	{
    			new JFrameCalculadora();
    	}	
    
}