t1.setText(String.valueOf(v)); is not interactive than t2.setText(String.valueOf(v)) Here if i press one integer(two it will show both previous and current integer) valueu t1 doesn't show,but t2 will give the immidiate reflection on data change
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class aacal extends Applet implements ActionListener{
static int cv,pv,v,res;
String cap;
Button b1=new Button("1");
Button b2=new Button("2");
Button b3=new Button("+");
Button b4=new Button("=");
TextField t1=new TextField(10);
TextField t2=new TextField(10);
public void init(){
// This textfield is to display the result and integer on buttons
add(t1);
t1.addActionListener(this);
t1.setText("0");
b1.addActionListener(this);
add(b1);
b2.addActionListener(this);
add(b2);
b3.addActionListener(this);
add(b3);
b4.addActionListener(this);
add(b4);
//This textfield is to display the ActionCommand on buttons
add(t2);
t2.addActionListener(this);
t2.setText("0");
}
public void actionPerformed(ActionEvent ae){
cap=ae.getActionCommand();
try{
cv=Integer.parseInt(t2.getText());
v=cv*10+Integer.parseInt(cap);
t2.setText(String.valueOf(v));
t1.setText(String.valueOf(v));
}catch(NumberFormatException ne){
try{
t2.setText(cap);
}catch(NumberFormatException e){
t2.setText("BYE");
}
}
switch(cap){
case "+":
pv=cv;
break;
case"=":
res=cv+pv;
t1.setText(String.valueOf(res));
break;
}
}
}