Ola, meu professor mando agente fazer uma calculadora igual do windows mas somente com 4 operações basicas: soma, subtração , mutiplicação e divisão então eu fiz mas quando chega nessas operações eu não sei muito bem como fazer no if , alguem poderia me dar uma luz?
[code] import javax.swing.;
import java.awt.;
import java.awt.event.*;
public class Calculadora extends JFrame implements ActionListener{
JButton botao;
JButton botao1;
JButton botao2;
JButton botao3;
JButton botao4;
JButton botao5;
JButton botao6;
JButton botao7;
JButton botao8;
JButton botao9;
JButton botao10;
JButton botao11;
JButton botao12;
JButton botao13;
JButton botao14;
JButton botao15;
JTextField texto;
// Método Construtor
public Calculadora(){
Container caixa = getContentPane();
caixa.setLayout(new FlowLayout());
// Instanciação de objetos
botao = new JButton("C");
botao1 = new JButton("=");
botao2 = new JButton("+");
botao3 = new JButton("-");
botao4 = new JButton("*");
botao5 = new JButton("/");
botao6 = new JButton("7");
botao7 = new JButton("8");
botao8 = new JButton("9");
botao9 = new JButton("4");
botao10 = new JButton("5");
botao11 = new JButton("6");
botao12 = new JButton("1");
botao13 = new JButton("2");
botao14 = new JButton("3");
botao15 = new JButton("0");
texto = new JTextField(10);
// Inclusão no container
caixa.add(texto);
caixa.add(botao);
caixa.add(botao1);
caixa.add(botao2);
caixa.add(botao3);
caixa.add(botao4);
caixa.add(botao5);
caixa.add(botao6);
caixa.add(botao7);
caixa.add(botao8);
caixa.add(botao9);
caixa.add(botao10);
caixa.add(botao11);
caixa.add(botao12);
caixa.add(botao13);
caixa.add(botao14);
caixa.add(botao15);
// Registro no listener dos objetos controlados
botao.addActionListener(this);
botao1.addActionListener(this);
botao2.addActionListener(this);
botao3.addActionListener(this);
botao4.addActionListener(this);
botao5.addActionListener(this);
botao6.addActionListener(this);
botao7.addActionListener(this);
botao8.addActionListener(this);
botao9.addActionListener(this);
botao10.addActionListener(this);
botao11.addActionListener(this);
botao12.addActionListener(this);
botao13.addActionListener(this);
botao14.addActionListener(this);
botao15.addActionListener(this);
// Ajustes finais do frame
setTitle("Calculadora");
setSize(193,104);
setVisible(true);
}
public void actionPerformed(ActionEvent evento)
{
//JOptionPane.showMessageDialog(null, getSize());
if(evento.getSource() == botao)
{
int c;
c = Integer.parseInt(texto.getText());
//c
texto.setText(""+c);
}
else if(evento.getSource() == botao1)
{
int valor;
int igual;
valor = Integer.parseInt(texto.getText());
igual = valor;
texto.setText(""+igual);
}
else if(evento.getSource() == botao2)
{
int valor1;
int valor2;
int soma;
valor1 = Integer.parseInt(texto.getText());
valor2 = Integer.parseInt(texto.getText());
soma = valor1 + valor2;
texto.setText(""+soma);
}
else if(evento.getSource() == botao3)
{
int valor1;
int valor2;
int subtrair;
valor1 = Integer.parseInt(texto.getText());
valor2 = Integer.parseInt(texto.getText());
subtrair = (valor1 - valor2);
texto.setText(""+subtrair);
}
else if(evento.getSource() == botao4)
{
int valor1;
int valor2;
int mutiplicar;
valor1 = Integer.parseInt(texto.getText());
valor2 = Integer.parseInt(texto.getText());
mutiplicar = (valor1 * valor2);
texto.setText(""+mutiplicar);
}
else if(evento.getSource() == botao5)
{
int valor1;
int valor2;
int dividir;
valor1 = Integer.parseInt(texto.getText());
valor2 = Integer.parseInt(texto.getText());
dividir = (valor1 / valor2);
texto.setText(""+dividir);
}
else if(evento.getSource() == botao15)
{
int numero;
numero = 0;
texto.setText(""+numero);
}
else if(evento.getSource() == botao12)
{
int numero;
numero = 1;
texto.setText(""+numero);
}
else if(evento.getSource() == botao13)
{
int numero;
numero = 2;
texto.setText(""+numero);
}
else if(evento.getSource() == botao14)
{
int numero;
numero = 3;
texto.setText(""+numero);
}
else if(evento.getSource() == botao9)
{
int numero;
numero = 4;
texto.setText(""+numero);
}
else if(evento.getSource() == botao10)
{
int numero;
numero = 5;
texto.setText(""+numero);
}
else if(evento.getSource() == botao11)
{
int numero;
numero = 6;
texto.setText(""+numero);
}
else if(evento.getSource() == botao6)
{
int numero;
numero = 7;
texto.setText(""+numero);
}
else if(evento.getSource() == botao7)
{
int numero;
numero = 8;
texto.setText(""+numero);
}
else if(evento.getSource() == botao8)
{
int numero;
numero = 9;
texto.setText(""+numero);
}
} // Fecha o método actionPerformed
public static void main(String args[])
{
Calculadora calc = new Calculadora();
calc.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
} // Fecha o método main()
}[/code]