ImageVerifierCode 换一换
格式:DOCX , 页数:18 ,大小:36.21KB ,
资源ID:19531779      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/19531779.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Java课程设计简易计算器修Word下载.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

Java课程设计简易计算器修Word下载.docx

1、程序主窗体继承JFrame类,使用24个JBotton按钮实现数字和基本功能,并且分别注册监听,采用6行4列网格布局,完成计算器界面的基本设置,最后对按钮进行计算分析,计算并显示结果。这段代码主要是对程序的主框架进行相应的设置super(简易计算器); setSize(300,260); this.setLayout(new BorderLayout(); jPanel1=new JPanel(); jPanel1.setLayout(new GridLayout(1,1); /一行一列的布局 jPanel2=new JPanel(); jPanel2.setLayout(new GridLa

2、yout(6,4); /六行四列的布局 resultField=new JTextField(0 jPanel1.add(resultField); this.add(jPanel1,BorderLayout.NORTH); this.add(jPanel2,BorderLayout.CENTER);设置数字按钮1到9并添加监控以及符号等的添加监控 s1=new JButton( 1 s1.addActionListener(this); s2=new JButton( 2 s2.addActionListener(this); s3=new JButton( 3 s3.addActionLi

3、stener(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 JBu

4、tton( 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); b5=new JButton( b5.addActionListener(this); b6=new JButton( 开方 b6.addActionListe

5、ner(this); b7=new JButton( % b7.addActionListener(this); b8=new JButton( x! b8.addActionListener(this); b9=new JButton( 1/x b9.addActionListener(this); f1=new JButton( . f1.addActionListener(this); f2=new JButton( = f2.addActionListener(this); f3=new JButton( C f3.addActionListener(this); f4=new JBu

6、tton( 负 f4.addActionListener(this); f5=new JButton( 退格 f5.addActionListener(this); jPanel2.add(f3); jPanel2.add(b4); jPanel2.add(b3); jPanel2.add(f5); jPanel2.add(s7); jPanel2.add(s8); jPanel2.add(s9); jPanel2.add(b1); jPanel2.add(s4); jPanel2.add(s5); jPanel2.add(s6); jPanel2.add(b2); jPanel2.add(s

7、1); jPanel2.add(s2); jPanel2.add(s3); jPanel2.add(b5); jPanel2.add(s0); jPanel2.add(f1); jPanel2.add(f4); jPanel2.add(b6); jPanel2.add(b7); jPanel2.add(b8); jPanel2.add(b9); jPanel2.add(f2);(3)数据输入用方法num(int i)设计如下:public void num(int i) String s = null; s=String.valueOf(i); /返回整数i的字符串表示形式 if(end) /

8、如果数字输入结束,则将文本框置零,重新输入 resultField.setText( end=false; if(resultField.getText().equals() /如果文本框的内容为零,则覆盖文本框的内容 resultField.setText(s); else /如果文本框的内容不为零,则在内容后面添加数字 str = resultField.getText() + s; resultField.setText(str); 以及用JFrame的方法actionPerformed(ActionEvent e)来获取数据(4)符号运算及清零、退格的设计如下: if(add) / 加

9、法 num1=num1 +num2; else if(sub) /减法 num1=num1 - num2; else if(mul) /乘法 num1=num1 * num2; else if(div) /除法 if (num2=0) throw new ArithmeticException(除数不能为零 else num1=num1 / num2; else if(chf) /乘方 if(num2=0) num1=1; num1=Math.pow(num1, num2); else if(evo) /开方 if(num20) throw new ArithmeticException(被开

10、方数不能小于零 else num1=Math.sqrt(num2); else if(rec) /倒数分母不能小于零 else num1=1/num2; else if(per) /百分 num1=num1/100.0; else if(pur) /阶乘负数不能求阶乘 else for(int i=1;inum2;i+) num1=i*num1; resultField.setText(String.valueOf(num1); end=true; else if(e.getSource()=f3) /实现清零 else if(e.getSource()=f4) /实现负号 if(result

11、Field.getText()!=)-+resultField.getText(); else if(e.getSource()=f5) /实现退格 int i; i=(resultField.getText().length(); if(i=1) resultField.setText( else str=resultField.getText(); resultField.setText(str.substring(0,i-1);五、程序设计import java.awt.*; import java.awt.event.*; import javax.swing.*; public cl

12、ass test1 extends JFrame implements ActionListener / JFrame jframe1; JPanel jPanel1,jPanel2; JTextField resultField; JButton s1,s2,s3,s4,s5,s6,s7,s8,s9,s0,b1,b2,b3,b4,b5,b6,b7,b8,b9,f1,f2,f3,f4,f5; private boolean end,add,sub,mul,div,evo,chf,per,rec,pur;private String str;private double num1,num2; p

13、ublic test1() super( /四行五列的布局 public void num(int i) if(end) /如果数字输入结束,则将文本框置零,重新输入 else /如果文本框的内容不为零,则在内容后面添加数字 public void actionPerformed(ActionEvent e)throws ArithmeticException /数字事件 if(e.getSource()=s1) num(1); else if(e.getSource()=s2) num(2); else if(e.getSource()=s3) num(3); else if(e.getSo

14、urce()=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); e

15、lse if(e.getSource()=b3) sign(3); else if(e.getSource()=b4) sign(4); else if(e.getSource()=b5) sign(5); else if(e.getSource()=b6) sign(6); else if(e.getSource()=b7) sign(7); else if(e.getSource()=b8) sign(8); else if(e.getSource()=b9) sign(9); else if(e.getSource()=f1) /实现. str=resultField.getText(); if(str.indexOf()=1) str+=; resultField.setText(str); else if(e.getSource()=f2) /实现 num2=Double.parseDouble(resultField.getText(); num1=num1 +num2; else if(sub) /减法 num1=num1 - num2; resultField.setText(str.

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1