📄 buttonlistener.txt
字号:
package frame;
import java.awt.Toolkit;
import java.awt.event.*;
import java.awt.event.*;
public class ButtonListener implements ActionListener{
Cal a;
Model modle;
public ButtonListener(Cal a,Model modle) {
super();
this.modle=modle;
this.a = a;
}
public void registerModel(Model m){
this.modle=m;
}
public void actionPerformed(ActionEvent E) {
if(("0123456789.").indexOf(E.getActionCommand())>=0){
a.setTxt(E.getActionCommand());
}else if(("+-*/").indexOf(E.getActionCommand())>=0) {
String op=a.getTxt();
modle.a1=Integer.parseInt(op);
a.clearTxt();
}else if(E.getActionCommand().equals("=")) {
String op=a.getTxt();
modle.a2=Integer.parseInt(op);
a.clearTxt();
if(("+").indexOf(E.getActionCommand())>=0)
a.setTxt(Double.toString(modle.add()));
else if(("-").indexOf(E.getActionCommand())>=0)
a.setTxt(Double.toString(modle.plus()));
else if(("*").indexOf(E.getActionCommand())>=0)
a.setTxt(Double.toString(modle.che()));
else if(("/").indexOf(E.getActionCommand())>=0)
a.setTxt(Double.toString(modle.chu()));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -