Reputation: 227
its basically a button event that does multiplication
mul.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if(Sans == null){
temp = text;
}else {
temp = Sans ;
}
text = "";
equal = "mul" ;
textArea.setText("*");
}
});
this is the action that happens when pressing equal button
ans.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if(equal == "mul"){
double a = Double.parseDouble(text);
double b = Double.parseDouble(temp);
double ans = b*a;
String Sans = String.valueOf(ans);
textArea.setText(Sans);
text = "" ;
}
}
this code gives the result for the first multiplication but gives a numberformatexception on successive multiplication the same code works fine doing a divide operation.
Upvotes: -3
Views: 168
Reputation: 68715
Update your if condition from
if(equal == "mul")
to
if(equal.equals("mul"))
Upvotes: 1