它基本上是一个做乘法的按钮事件
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 = "" ;
}
}
这段代码给出了第一次乘法的结果,但在连续乘法上给出了一个 numberformatexception 相同的代码可以很好地执行除法运算。