为了正常的体验网站,请在浏览器设置里面开启Javascript功能!
首页 > 计算器 五个键的计算器

计算器 五个键的计算器

2017-12-21 5页 doc 23KB 18阅读

用户头像

is_477730

暂无简介

举报
计算器 五个键的计算器计算器 五个键的计算器 五个键的计算器代码: import java.awt.*; import java.awt.event.*; import javax.swing.*; class calculator1 implements ActionListener { static JFrame f11=new JFrame("计算器"); JPanel p1=new JPanel(); static JTextArea t1=new JTextArea(3,5); JButton a=new JButto...
计算器 五个键的计算器
计算器 五个键的计算器 五个键的计算器代码: import java.awt.*; import java.awt.event.*; import javax.swing.*; class calculator1 implements ActionListener { static JFrame f11=new JFrame("计算器"); JPanel p1=new JPanel(); static JTextArea t1=new JTextArea(3,5); JButton a=new JButton("1"); JButton b=new JButton("2"); JButton c=new JButton("3"); JButton d=new JButton("+"); JButton e=new JButton("="); String x="",zz="",z=""; double cc=0.0,ss=0.0,xx=0.0,aa=0.0; void calculator11() { f11.setLayout(new BorderLayout(5,5)); p1.setLayout(new GridLayout(1,5,5,5)); p1.add(a); p1.add(b); p1.add(c); p1.add(d); p1.add(e); f11.add(t1,"North"); f11.add(p1,"Center"); a.addActionListener(this); b.addActionListener(this); c.addActionListener(this); d.addActionListener(this); e.addActionListener(this); f11.setSize(300,150); p1.setSize(300,100); f11.setVisible(true); p1.setVisible(true); t1.setVisible(true); } public void actionPerformed(ActionEvent e11) //实现接口函数 { if(e11.getActionCommand().equals("1")) { x=x+"1"; t1.setText(zz+x); } if(e11.getActionCommand().equals("2")) { x=x+"2"; t1.setText(zz+x); } if(e11.getActionCommand().equals("3")) { x=x+"3"; t1.setText(zz+x); } if(e11.getActionCommand().equals("+")) { if(x==""||zz+x=="") t1.setText("请先输入第一个加数~"); else { ss=Double.parseDouble(x); aa=aa+ss; zz=zz+x+"+"; t1.setText(zz); x=""; z="+"; } } if(e11.getActionCommand().equals("=")) { if(z.equals("")) { t1.setText(x+"="+"\n"+x); } else { xx=Double.parseDouble(x); cc=aa+xx; t1.setText(zz+x+'\n'+'='+Double.toString(cc)); } x=""; zz=""; z=""; aa=0; } } } public class calculator2 { public static void main(String args[]) { calculator1 cc=new calculator1(); cc.calculator11(); } } 运行结果:
/
本文档为【计算器 五个键的计算器】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
热门搜索

历史搜索

    清空历史搜索