buttonlistener.txt
来自「这是一个用java编写的关于GUI应用编程的简单的计算器的样例」· 文本 代码 · 共 47 行
TXT
47 行
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 + =
减小字号Ctrl + -
显示快捷键?