⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 buttonlistener.txt

📁 这是一个用java编写的关于GUI应用编程的简单的计算器的样例
💻 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 + -