/**
 * @(#)Text1.java
 *
 *
 * @author 
 * @version 1.00 2017/3/28
 */
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;

public class CalculadoraSimples extends JFrame implements ActionListener
{
	JPanel Painel_Norte, Painel_Sul, Painel_Centro, Painel_Leste, Painel_Oeste;
	JPanel Painel_Oeste1,Painel_Oeste2, Painel_Oeste3;
	JPanel Painel_Leste1, Painel_Leste2, Painel_Leste3;
	JPanel Painel_Centro1, Painel_Centro2, Painel_Centro3;
	JButton bt_Somar, bt_Diminuir, bt_Dividir, bt_Multiplicar,bt_Limpar;
	JLabel lbl_Resultado;
	JTextField txt_Valor1, txt_Valor2;
    public CalculadoraSimples() 
    {
    	setLayout(new BorderLayout());
    	getContentPane().setBackground(Color.orange);
    	getContentPane().add("East", Painel_Leste = new JPanel(new GridLayout(3,1)) );
    	Painel_Leste.add(Painel_Leste1 = new JPanel(new FlowLayout(FlowLayout.CENTER)));
    	Painel_Leste1.add(bt_Somar = new JButton("+"));
    	Painel_Leste1.add(bt_Diminuir = new JButton("-"));
    	
    	Painel_Leste.add(Painel_Leste2 = new JPanel(new FlowLayout(FlowLayout.CENTER)));
    	Painel_Leste2.add(bt_Dividir = new JButton("/"));
    	Painel_Leste2.add(bt_Multiplicar = new JButton("*"));
    	
    	Painel_Leste.add(Painel_Leste3  = new JPanel(new FlowLayout(FlowLayout.CENTER)));
    	Painel_Leste3.add(bt_Limpar = new JButton("Limpar"));
    	getContentPane().add("West", Painel_Oeste = new JPanel(new GridLayout(3, 1)));
    	Painel_Oeste.add(Painel_Oeste1 = new JPanel (new FlowLayout(FlowLayout.RIGHT)));
    	Painel_Oeste1.add(new JLabel("Valor 1:"));
    	Painel_Oeste.add(Painel_Oeste2 = new JPanel (new FlowLayout(FlowLayout.RIGHT)));
    	Painel_Oeste2.add(new JLabel("Valor 2:"));
    	Painel_Oeste.add(Painel_Oeste3 = new JPanel (new FlowLayout(FlowLayout.RIGHT))); 
    	Painel_Oeste3.add(new JLabel("Resultado:"));    		   	
    	getContentPane().add("Center", Painel_Centro = new JPanel(new GridLayout(3, 1)));
    	Painel_Centro.add(Painel_Centro1 = new JPanel (new FlowLayout(FlowLayout.LEFT)));
    	Painel_Centro1.add(txt_Valor1 = new JTextField(20));
    	Painel_Centro.add(Painel_Centro2 = new JPanel (new FlowLayout(FlowLayout.LEFT)));
    	Painel_Centro2.add(txt_Valor2 = new JTextField(20));
    	Painel_Centro.add(Painel_Centro3 = new JPanel (new FlowLayout(FlowLayout.LEFT)));	
    	Painel_Centro3.add(lbl_Resultado = new JLabel ("Aguardando digitação de valores"));
    		lbl_Resultado.setBackground(Color.black);
    	bt_Somar.addActionListener(this);
    	bt_Diminuir.addActionListener(this);
    	bt_Dividir.addActionListener(this);
    	bt_Multiplicar.addActionListener(this);
    	bt_Limpar.addActionListener(this);
    	setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    	setResizable(false);	
    		
 	
    		
    	setTitle("CALCULADORA SIMPLES");
    	pack();
    	setVisible(true);
    	
    }
    public static void main (String args [])
    {
    	new CalculadoraSimples();
    	
    }	
    
    public void actionPerformed (ActionEvent e)
    {
    
    	String Caixa1 = txt_Valor1.getText();
    	double  Resultado;
    	double Valor1 = Double.parseDouble((Caixa1));
    	String Caixa2 = txt_Valor2.getText();
    	double Valor2 = Double.parseDouble(Caixa2);
    	    	
    	if(e.getSource()==bt_Somar)
    	{
    	      
    		lbl_Resultado.setText(""+(Valor1+Valor2));		
    	}
        if(e.getSource()==bt_Diminuir)
    	{
    	      
    		lbl_Resultado.setText(""+ (Valor1 - Valor2));		
    	}
        if(e.getSource()==bt_Multiplicar)
    	{
    	      
    		lbl_Resultado.setText(""+(Valor1 * Valor2));		
    	}
        if(e.getSource()==bt_Dividir)
    	{
    	      
    		lbl_Resultado.setText(""+(Valor1/Valor2));		
    	}	
    	    	
    	if(e.getSource()==bt_Limpar)
    	{
    	      //Resultado = Valor1 + Valor2; 
    		lbl_Resultado.setText("Aguardando digitação de valores");
    		if(txt_Valor1.equals(""))
    			{/*NAO FAÇA NADA*/}
    		else
    			{txt_Valor1.setText("");}
    		if(txt_Valor2.getText().equals(""))
    			{/*NAO FAÇA NADA*/}
    		else
    			{txt_Valor2.setText(" ");}		
    	} 
    		   	
    		
    }
		
    
}