Estou desenvolvendo um simples calculadora em java, com interface para teclado e mouse, mas estou com mtos problesmas aguem pode me dar uma ajuda!?? O consegui desenvolver ate aki:
[code]import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JButton;
public class Calcl extends JFrame
{
private JPanel p1,p2;
private JTextField visor;
private JButton um,dois,tres,quatro,cinco,seis,sete,oito,nove,zero,ponto,igual,mais,menos,divisao,multi;
private String aux = "";
private String aux2 = "";
private Double op1;
private Double op2;
private int operacao;
private boolean sinal;
private Double total;
public Calcl()
{
super("Calculadora JAVA");
setLayout(new BorderLayout());
p1 = new JPanel();
p1.setLayout(new FlowLayout(FlowLayout.CENTER));
visor = new JTextField(20);
visor.setHorizontalAlignment(JTextField.RIGHT);
p1.add(visor);
p2= new JPanel();
p2.setLayout(new GridLayout(4,4,1,1));
sete = new JButton("7");
p2.add(sete);
oito = new JButton("8");
p2.add(oito);
nove = new JButton("9");
p2.add(nove);
divisao = new JButton("/");
p2.add(divisao);
quatro = new JButton("4");
p2.add(quatro);
cinco = new JButton("5");
p2.add(cinco);
seis = new JButton("6");
p2.add(seis);
multi = new JButton("*");
p2.add(multi);
um = new JButton("1");
p2.add(um);
dois = new JButton("2");
p2.add(dois);
tres = new JButton("3");
p2.add(tres);
menos = new JButton("-");
p2.add(menos);
zero = new JButton("0");
p2.add(zero);
ponto = new JButton(".");
p2.add(ponto);
igual = new JButton("=");
p2.add(igual);
mais = new JButton("+");
p2.add(mais);
add(BorderLayout.NORTH,p1);
add(BorderLayout.SOUTH,p2);
TecladoNum trat = new TecladoNum();
sete.addActionListener(trat);
oito.addActionListener(trat);
nove.addActionListener(trat);
quatro.addActionListener(trat);
cinco.addActionListener(trat);
seis.addActionListener(trat);
um.addActionListener(trat);
dois.addActionListener(trat);
tres.addActionListener(trat);
zero.addActionListener(trat);
TecladoNum2 trat2 = new TecladoNum2();
divisao.addActionListener(trat2);
multi.addActionListener(trat2);
menos.addActionListener(trat2);
mais.addActionListener(trat2);
igual.addActionListener(trat2);
}
private class TecladoNum implements ActionListener
{
public void actionPerformed (ActionEvent e)
{
if(e.getActionCommand().equals("7"))
{
aux+= e.getActionCommand();
}
else{
if(e.getActionCommand().equals("8"))
{
aux+= e.getActionCommand();
}
else
if(e.getActionCommand().equals("9"))
{
aux+= e.getActionCommand();
}
else
if(e.getActionCommand().equals("4"))
{
aux+= e.getActionCommand();
}
else
if(e.getActionCommand().equals("5"))
{
aux+= e.getActionCommand();
}
else
if(e.getActionCommand().equals("6"))
{
aux+= e.getActionCommand();
}
else
if(e.getActionCommand().equals("1"))
{
aux+= e.getActionCommand();
}
else
if(e.getActionCommand().equals("2"))
{
aux+= e.getActionCommand();
}
else
if(e.getActionCommand().equals("3"))
{
aux+= e.getActionCommand();
}
else
if(e.getActionCommand().equals("0"))
{
aux+= e.getActionCommand();
}
if(e.getActionCommand().equals("."))
{
aux+= e.getActionCommand();
}
visor.setText(aux);
}
}
}
private class TecladoNum2 implements ActionListener
{
public void actionPerformed (ActionEvent e)
{
if(e.getActionCommand().equals("/"))
{
op1=Double.parseDouble(visor.getText());
operacao = 1;
sinal = false;
}
else{
if(e.getActionCommand().equals("*"))
{
op1=Double.parseDouble(visor.getText());
operacao = 2;
sinal = false;
}
else
if(e.getActionCommand().equals("+"))
{
op1=Double.parseDouble(visor.getText());
operacao = 3;
sinal = false;
}
else
if(e.getActionCommand().equals("-"))
{
op1=Double.parseDouble(visor.getText());
operacao = 4;
sinal = false;
}
else
if (e.getActionCommand().equals("="));
{
switch (operacao)
{
case 1 : total = op1/op2;
case 2 : total = op1*op2;
case 3 : total = op1+op2;
case 4 : total = op1-op2;
visor.setText(String.valueOF(total));
}
}
}
}
}
public static void main(String args[])
{
JFrame app = new Calcl();
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
app.pack();
app.setVisible(true);
}
}[/code]