import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;


public class OperacoesMatematicas extends JFrame implements ActionListener
{
	JButton bt_Sair, bt_Potencia, bt_Multiplicar, bt_Dividir, bt_Subtrair, bt_Adicionar, bt_Limpar;
	JPanel Painel_Norte, Painel_Sul; 
	JPanel Painel_Centro,  Painel_Centro1,  Painel_Centro2,  Painel_Centro3,  Painel_Centro4;	
	JTextField tf_Primeiro_Numero, tf_Segundo_Numero, tf_Resultado;
	public OperacoesMatematicas()
	{
		getContentPane().setLayout(new BorderLayout());
		getContentPane().add("North", Painel_Norte = new JPanel(new FlowLayout(FlowLayout.LEFT)));
		Painel_Norte.add(new JLabel("OPERAÇÕES MATEMÁTICAS")); 
		getContentPane().add("Center",  Painel_Centro = new JPanel(new GridLayout(4, 1)));
		Painel_Centro.add(Painel_Centro1 = new JPanel (new FlowLayout(FlowLayout.RIGHT)));
		Painel_Centro1.add(new JLabel("Primeiro Número:"));
		Painel_Centro1.add(tf_Primeiro_Numero = new JTextField("0",15)); 
		Painel_Centro.add(Painel_Centro2 = new JPanel (new FlowLayout(FlowLayout.RIGHT)));
		Painel_Centro2.add(new JLabel("Segundo Número:"));
		Painel_Centro2.add(tf_Segundo_Numero = new JTextField("0",15));
		Painel_Centro.add(Painel_Centro3 = new JPanel (new FlowLayout(FlowLayout.RIGHT)));
		Painel_Centro3.add(new JLabel("Resultado:"));
		Painel_Centro3.add(tf_Resultado = new JTextField("0",15));
		tf_Resultado.setEditable(false);		
		Painel_Centro.add(Painel_Centro4 = new JPanel (new FlowLayout(FlowLayout.CENTER)));
		Painel_Centro4.add(bt_Adicionar = new JButton("+")); 
		Painel_Centro4.add(bt_Multiplicar = new JButton("*"));
		Painel_Centro4.add(bt_Dividir = new JButton("/"));
		Painel_Centro4.add(bt_Subtrair = new JButton("-"));
		Painel_Centro4.add(bt_Potencia = new JButton("^")); 
		
		getContentPane().add("South", Painel_Sul = new JPanel(new FlowLayout(FlowLayout.RIGHT)));
		Painel_Sul.add(bt_Limpar = new JButton("Limpar"));
		Painel_Sul.add(bt_Sair = new JButton ("Sair"));	
		bt_Sair.addActionListener(this);
		bt_Adicionar.addActionListener(this);
		bt_Limpar.addActionListener(this);
		bt_Multiplicar.addActionListener(this);
		bt_Dividir.addActionListener(this);
		bt_Subtrair.addActionListener(this);
		bt_Potencia.addActionListener(this);
		
		
		pack();
		setResizable(false);
		setVisible(true);
	}	
	public void actionPerformed (ActionEvent e)
	{
		double Primeiro_Numero = Double.parseDouble(tf_Primeiro_Numero.getText());
		double Segundo_Numero = Double.parseDouble(tf_Segundo_Numero.getText()); 
		double Resultado = 0; 
		if(e.getSource()==bt_Multiplicar)
		{
				Resultado = Primeiro_Numero * Segundo_Numero;
				tf_Resultado.setText(""+Resultado);
		}	
		if(e.getSource()==bt_Dividir)
		{
				Resultado = Primeiro_Numero / Segundo_Numero;
				tf_Resultado.setText(""+Resultado);
		}	
		if(e.getSource()==bt_Subtrair)
		{
				Resultado = Primeiro_Numero - Segundo_Numero;
				tf_Resultado.setText(""+Resultado);
		}	
		if(e.getSource()==bt_Potencia)
		{
				Resultado = Math.pow(Primeiro_Numero, Segundo_Numero);
				tf_Resultado.setText(""+Resultado);
		}	
		
		if(e.getSource()==bt_Sair)
		{
			System.exit(0);
		}
		if(e.getSource()==bt_Adicionar)
		{
			Resultado = Primeiro_Numero + Segundo_Numero; 
			tf_Resultado.setText(""+Resultado);	 	
			
		}
		if(e.getSource()==bt_Limpar)
		{
			 tf_Primeiro_Numero.setText("");
			 tf_Segundo_Numero.setText("");
			 tf_Resultado.setText("");		
		}						
	}		
	public static void main (String args [])
	{
		new OperacoesMatematicas();
	}		
}

