《JAVA程序设计》实验报告(DOC)(4)
private JTextField resultField; private JButton s1,s2,s3,s4,s5,s6,s7,s8,s9,s0,b1,b2,b3,b4,f1,f2; private boolean end,add,sub,mul,div; private String str; private double num1,num2; public Calculater(){ super(\ setSize(300,240); Container con=getContentPane(); con.setLayout(new BorderLayout()); jPanel1=new JPanel(); jPanel1.setLayout(new GridLayout(1,1)); jPanel2=new JPanel(); jPanel2.setLayout(new GridLayout(4,4)); resultField=new JTextField(\ jPanel1.add(resultField); con.add(jPanel1,BorderLayout.NORTH); s1=new JButton(\ 1 \ s1.addActionListener(this); s2=new JButton(\ 2 \ s2.addActionListener(this); s3=new JButton(\ 3 \ s3.addActionListener(this); s4=new JButton(\ 4 \ s4.addActionListener(this); s5=new JButton(\ 5 \ s5.addActionListener(this); s6=new JButton(\ 6 \ s6.addActionListener(this); s7=new JButton(\ 7 \ s7.addActionListener(this); s8=new JButton(\ 8 \ s8.addActionListener(this); s9=new JButton(\ 9 \ s9.addActionListener(this); s0=new JButton(\ 0 \ s0.addActionListener(this); b1=new JButton(\ + \ b1.addActionListener(this); b2=new JButton(\ - \ b2.addActionListener(this); b3=new JButton(\ * \ b3.addActionListener(this); b4=new JButton(\ / \ b4.addActionListener(this); f1=new JButton(\ . \ f1.addActionListener(this); f2=new JButton(\ = \ f2.addActionListener(this); jPanel2.add(s1); jPanel2.add(s2); jPanel2.add(s3); jPanel2.add(b1); jPanel2.add(s4); jPanel2.add(s5); jPanel2.add(s6); jPanel2.add(b2); jPanel2.add(s7); jPanel2.add(s8); jPanel2.add(s9); jPanel2.add(b3); jPanel2.add(s0); jPanel2.add(f1); jPanel2.add(f2); jPanel2.add(b4); con.add(jPanel2,BorderLayout.CENTER); } public void num(int i){ String s = null; s=String.valueOf(i); if(end){ //如果数字输入结束,则将文本框置零,重新输入 resultField.setText(\ end=false; } if((resultField.getText()).equals(\ //如果文本框的内容为零,则覆盖文本框的内容 resultField.setText(s); } else{ //如果文本框的内容不为零,则在内容后面添加数字 str = resultField.getText() + s; resultField.setText(str); } } public void actionPerformed(ActionEvent e){ //数字事件 if(e.getSource()==s1) num(1); else if(e.getSource()==s2) num(2); else if(e.getSource()==s3) num(3); else if(e.getSource()==s4) num(4); else if(e.getSource()==s5) num(5); else if(e.getSource()==s6) num(6); else if(e.getSource()==s7) num(7); else if(e.getSource()==s8) num(8); else if(e.getSource()==s9) num(9); else if(e.getSource()==s0) num(0); //符号事件 else if(e.getSource()==b1) sign(1); else if(e.getSource()==b2) sign(2); else if(e.getSource()==b3) sign(3); else if(e.getSource()==b4) sign(4); //等号 else if(e.getSource()==f1){ str=resultField.getText(); if(str.indexOf(\ str+=\ resultField.setText(str); } } else if(e.getSource()==f2){ num2=Double.parseDouble(resultField.getText()); if(add){ num1=num1 + num2;} else if(sub){
…… 此处隐藏:726字,全部文档内容请下载后查看。喜欢就下载吧 ……相关推荐:
- [实用模板]第八章:法国“新浪潮”与“左岸派”
- [实用模板]2021年北京上半年临床医学检验技师生物
- [实用模板]SAP GUI 7.10客户端安装配置文档
- [实用模板]2001年临床执业医师资格考试综合笔试试
- [实用模板]36机场工作实用英语词汇总结
- [实用模板](一)社会保险稽核通知书
- [实用模板]安全教育主题班会材料
- [实用模板]濉溪县春季呼吸道传染病防控应急演练方
- [实用模板]长沙房地产市场周报(1.30-2.3)
- [实用模板]六年级数学上册典中点 - 图文
- [实用模板]C程序设计(红皮书)习题官方参考答案
- [实用模板]中国证监会第一届创业板发行审核委员会
- [实用模板]桥梁工程复习题
- [实用模板]2011学而思数学及答案
- [实用模板]初中病句修改专项练习
- [实用模板]监理学习知识1 - 图文
- [实用模板]小机灵杯四年级试题
- [实用模板]国贸专业毕业论文模板
- [实用模板]教育学概论考试练习题-判断题4
- [实用模板]2015届高考英语一轮复习精品资料(译林
- 00Nkmhe_市场营销学工商管理_电子商务_
- 事业单位考试法律常识
- 诚信教育实施方案
- 吉大小天鹅食品安全检测箱方案(高中低
- 房地产销售培训资料
- 高一地理必修1复习提纲
- 新概念英语第二册lesson_1_练习题
- 证券公司内部培训资料
- 小学英语时间介词专项练习
- 新世纪英语专业综合教程(第二版)第1册U
- 【新课标】浙教版最新2018年八年级数学
- 工程建设管理纲要
- 外研版 必修一Module 4 A Social Surve
- Adobe认证考试 AE复习资料
- 基于H.264AVC与AVS标准的帧内预测技术
- 《食品检验机构资质认定管理办法》(质
- ABB变频器培训课件
- (完整版)小学说明文阅读练习题及答案
- 深思洛克(SenseLock) 深思IV,深思4,深
- 弟子规全文带拼音




