Hola a todos, tengo el siguiente codigo, el problema es que me concatena 2 veces el caracter que presiono.
Código Java:
Ver originalimport java.awt.*;
import java.awt.event.*;
import static java.
lang.
Math.
*; import javax.swing.*;
public class Interfaz
extends JFrame { Interfaz(){
super("Calculadora");
//add(t3,BorderLayout.EAST);
char[] n={'7','8','9','+','4','5','6','-','1','2','3','/','0','c','=','*'};
for(int i=0;i<16;i++){
boton[i].addActionListener(new Responder());
}
for(int i=0;i<16;i++){
boton[i].addActionListener(new Responder());
}
/*
add(jl1=new JLabel("X"));
add(jl1=new JLabel("Y"));
add(jl1=new JLabel("Resultado"));
add(t1=new JTextField());
add(t2=new JTextField());
add(t3=new JTextField());
t3.setEditable(false);
a.addActionListener(new Responder());
b.addActionListener(new Responder());
c.addActionListener(new Responder());
d.addActionListener(new Responder());
e.addActionListener(new Responder());
f.addActionListener(new Responder());
g.addActionListener(new Responder());
h.addActionListener(new Responder());
i.addActionListener(new Responder());
/*JButton boton=new JButton();
add(boton);
boton.addActionListener(new OyenteBoton());*/
setSize(400,500);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main
(String args
[]){ Interfaz a=new Interfaz();
}
//Float aa=new Float(t1.getText());
//Float bb=new Float(t2.getText());
//float cc=0;
if(ss.equals("+")){
cad=cad+"+";
t1.setText(cad);
}
if(ss.equals("-")){
// cc=aa-bb;
}
if(ss.equals("*")){
// cc=aa*bb;
}
if(ss.equals("/")){
// cc=aa/bb;
}
if(ss.equals("1")){
cad=cad+"1";
}
if(ss.equals("2")){
cad=cad+"2";
}
if(ss.equals("3")){
cad=cad+"3";
}
if(ss.equals("4")){
cad=cad+"4";
}
if(ss.equals("5")){
cad=cad+"5";
}
if(ss.equals("6")){
cad=cad+"6";
}
if(ss.equals("7")){
cad=cad+"7";
}
if(ss.equals("8")){
cad=cad+"8";
}
if(ss.equals("9")){
cad=cad+"9";
}
if(ss.equals("0")){
cad=cad+"0";
}
if(ss.equals("c")){
cad="";
}
t1.setText(cad);
}
}
}