它基本上是一个进行乘法运算的按钮事件
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
从
更新if条件if(equal == "mul")
if(equal.equals("mul"))
学习更多关于字符串比较的知识。相关文章https://stackoverflow.com/questions/767372/java-string-equals-versus