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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

模拟科学计算器课程设计手稿.docx

1、模拟科学计算器课程设计手稿 面向对象课程设计 题目 学院 专业 班级 学号 姓名 指导老师 编写日期 目录 面向对象课程设计 - 1 -目录 - 2 -一、 需求分析 - 3 -二、 系统运行环境 - 3 -三、 简要设计 - 3 -四、 详细设计 - 4 -五、 程序调试 - 5 -六、总结 - 6 -七、附录 - 7 -1、需求分析 1.设计一个模拟科学计算器,界面要求模拟windows中的计算器程序。 2.要求实现基本数学运算、函数等功能,加、减、乘、除、阶乘、正弦、余弦和指数运算。 3.添加相关组件并进行按钮事件处理。2、系统运行环境 Windows 7以及Myeclipse8.63、

2、简要设计 模拟科学计算器界面设计如下:查看(V)编辑(E)帮助(H) 文本域 【显示数据(输入、输出)】CalucbackCECMCX2X3789/MRN!sqrt456*MSsinln123-M+coslog0.-/+M-tan%Expangle= 如上图所示,设计流程如下:1.菜单栏设计.2.文本域,即为计算器的屏幕显示区域3.初始化操作4.统一设置按钮的的使用方式5.计算器的基础操作(+ - * /)6.运算符号的事件监听7.清除按钮的事件监听8.数字输入的事件监听9.小数点的事件监听10.main方法4、详细设计主要函数模块及功能:1、主函数:public static void ma

3、in(String args) new Calucator01().setVisible(true);功能:调用公共类Calucator01,启动计算器。2、public Calucator01() 设计面板布局; 加入菜单栏(编辑、查看、帮助等); Init();功能:对计算器面板进行设计,并对于各按钮添加事件监听。3、private void init() 各按钮加入各容器; 版面布局; 功能:初始化。4、private void addButton(JPanel panel,String name,ActionListener action,Color color)功能:按钮加入容器,并

4、进行事件监听和颜色设置。5、private void getResult(double x)功能:基本运算,+ - * /等运算。6、class Signs implements ActionListener功能:对于运算符号按钮进行事件监听。7、class Clear implements ActionListener功能:对于清除按钮事件进行监听。8、class Num implements ActionListener功能:对于数字输入按钮进行事件监听。9、class Dot implements ActionListener功能:对于小数点按钮事件进行监听。5、程序调试效果图如下:1、

5、按顺序点击按钮3、*、9、=,显示结果27,点击C清零;2、按顺序点击按钮3、/、8、=,显示结果0.375,点击C清零;3、按顺序点击按钮360、-/+、6、=,显示结果-60,点击C清零;4、按顺序点击按钮30、angle、sin,显示结果0.5,点击C清零;5、按顺序点击按钮、cos,显示结果-1,点击C清零;6、按顺序点击按钮100、log10,显示结果2,点击C清零;7、按顺序点击按钮Exp、ln,显示结果1,点击C清零;8、按顺序点击按钮2、X2,显示结果4,点击C清零。其中精确度达到小数点后十位。六、总结 总的来说,这次的面向对象课程设计中学到不少图形界面设计方面的知识。首先,我

6、在老师上课没有涉及的知识领域中摸索着前进,一周下来的看书、上机操作以及和同学队友之间的交流,让我深深感受到java语言在图形界面设计上的优势和方便,从而获得强烈的求知欲,迫不及待地学完所涉及的章节;其次,这次的模拟科学计算器虽然能够实现单步的基本数学运算、函数、指数等运算,但是由于时间关系,考试在即,很遗憾没能够深入拓展实现复杂的带有括号的四则运算;最后,要感谢老师的指导和同学们的交流。七、附录源程序:import java.awt.*;import java.awt.event.*;import java.text.DecimalFormat;import javax.swing.*;pub

7、lic class Calucator01 extends JFrame private JTextField tf; private JPanel panelA,panelB,panelC,panelD; private JMenuBar mybar; private JMenu menuA,menuB,menuC; private JMenuItem ed1,ed2,help1,help2,help3; private JRadioButtonMenuItem seeItem1,seeItem2; private JCheckBoxMenuItem seeItem3; private Bu

8、ttonGroup bgb; private boolean IfResult = true,flag = false; private String oper = =; private double result = 0; private Num numActionListener; private DecimalFormat df; public Calucator01() super(模拟科学计算器);/设置标题 df = new DecimalFormat(#.#);/保留十位小数 this.setLayout(new BorderLayout(10,5); panelA = new

9、JPanel(new GridLayout(1,3,10,10);/back,CE,C panelB = new JPanel(new GridLayout(5,6,5,5); /X3 X2 7 8 9 / /N! sqrt 4 5 6 * /sin ln 1 2 3 - /cos log 0 . -/+ + /tan % Exp angle = panelC = new JPanel(new GridLayout(6,1,5,5); panelD = new JPanel(new BorderLayout(5,5); /*菜单栏*/ mybar = new JMenuBar(); menuA

10、 = new JMenu(查看(V); menuB = new JMenu(编辑(E); menuC = new JMenu(帮助(H); menuA.setFont(new Font(宋体,Font.PLAIN,12); menuB.setFont(new Font(宋体,Font.PLAIN,12); menuC.setFont(new Font(宋体,Font.PLAIN,12); /*编辑栏*/ ed1 = new JMenuItem(复制(C) Ctrl+C); ed2 = new JMenuItem(粘贴(P) Ctrl+V); ed1.setFont(new Font(宋体,Fo

11、nt.PLAIN,12); ed2.setFont(new Font(宋体,Font.PLAIN,12); /*查看栏*/ seeItem1 = new JRadioButtonMenuItem(标准型(S) Alt+1); seeItem2 = new JRadioButtonMenuItem(科学型(T) Alt+2); seeItem3 = new JCheckBoxMenuItem(数字分组(I); seeItem1.setFont(new Font(宋体,Font.PLAIN,12); seeItem2.setFont(new Font(宋体,Font.PLAIN,12); seeI

12、tem3.setFont(new Font(宋体,Font.PLAIN,12); /*帮助栏*/ help1 = new JMenuItem(查看主题(V) F1); help2 = new JMenuItem(关于计算器(A); help1.setFont(new Font(宋体,Font.PLAIN,12); help2.setFont(new Font(宋体,Font.PLAIN,12); bgb = new ButtonGroup();/选项组 menuA.add(seeItem1); menuA.add(seeItem2); menuA.addSeparator();/添加一条分割线

13、 menuA.add(seeItem3); menuB.add(ed1); menuB.add(ed2); menuC.add(help1); menuC.addSeparator(); menuC.add(help2); mybar.add(menuA); mybar.add(menuB); mybar.add(menuC); this.setJMenuBar(mybar); numActionListener = new Num();/实现数字监听 /*TextArea 计算器屏幕显示区域*/ tf = new JTextField(); tf.setEditable(false);/文本

14、区域不可编辑 tf.setBackground(Color.white);/文本区域的背景色 tf.setHorizontalAlignment(JTextField.RIGHT); tf.setText(0); tf.setBorder(BorderFactory.createLoweredBevelBorder(); init();/对计算器进行初始化 private void init() addButton(panelA,Backspace,new Clear(),Color.red); addButton(panelA,CE,new Clear(),Color.red); addBu

15、tton(panelA,C,new Clear(),Color.red); addButton(panelB,X2,new Signs(),Color.magenta); addButton(panelB,X3,new Signs(),Color.magenta); addButton(panelB,7,numActionListener,Color.blue); addButton(panelB,8,numActionListener,Color.blue); addButton(panelB,9,numActionListener,Color.blue); addButton(panelB

16、,/,new Signs(),Color.black); addButton(panelB,N!,new Signs(),Color.magenta); addButton(panelB,sqrt,new Signs(),Color.magenta); addButton(panelB,4,numActionListener,Color.blue); addButton(panelB,5,numActionListener,Color.blue); addButton(panelB,6,numActionListener,Color.blue); addButton(panelB,*,new

17、Signs(),Color.black); addButton(panelB,sin,new Signs(),Color.magenta); addButton(panelB,ln,new Signs(),Color.magenta); addButton(panelB,1,numActionListener,Color.blue); addButton(panelB,2,numActionListener,Color.blue); addButton(panelB,3,numActionListener,Color.blue); addButton(panelB,-,new Signs(),

18、Color.black); addButton(panelB,cos,new Signs(),Color.magenta); addButton(panelB,log10,new Signs(),Color.magenta); addButton(panelB,0,numActionListener,Color.blue); addButton(panelB,.,new Dot(),Color.blue); addButton(panelB,-/+,new Clear(),Color.blue); addButton(panelB,+,new Signs(),Color.black); add

19、Button(panelB,tan,new Signs(),Color.magenta); addButton(panelB,%,new Signs(),Color.magenta); addButton(panelB,numActionListener,Color.green); addButton(panelB,Exp,numActionListener,Color.green); addButton(panelB,angle,new Signs(),Color.green); addButton(panelB,=,new Signs(),Color.black); JButton btn

20、s = new JButton(); JLabel lb = new JLabel(Caluc); lb.setFont(new Font(宋体,Font.BOLD,15); btns.add(lb); btns.setBorder(BorderFactory.createLoweredBevelBorder(); btns.setEnabled(false);/按钮不可操作 btns.setPreferredSize(new Dimension(20,20); panelC.add(btns); addButton(panelC,MC,null,Color.gray); addButton(

21、panelC,MR,null,Color.gray); addButton(panelC,MS,null,Color.gray); addButton(panelC,M+,null,Color.gray); addButton(panelC,M-,null,Color.gray); panelD.add(panelA,BorderLayout.NORTH); panelD.add(panelB,BorderLayout.CENTER); this.add(tf,BorderLayout.NORTH); this.add(panelC,BorderLayout.WEST); this.add(p

22、anelD); pack(); this.setResizable(false);/窗口大小不可改变 this.setLocation(400,400); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); private void addButton(JPanel panel,String name,ActionListener action,Color color) JButton bt = new JButton(name); panel.add(bt); bt.setForeground(color); bt.addActionLi

23、stener(action); /计算器的基础操作/ private void getResult(double x) if(oper=+)result+=x; else if(oper=-)result-=x; else if(oper=*)result*=x; else if(oper=/)result/=x; else if(oper=)result=x; tf.setText(df.format(result); /*运算符号事件监听*/ class Signs implements ActionListener public void actionPerformed(ActionEv

24、ent e) String str = e.getActionCommand(); if(str.equals(sqrt) double i = Double.parseDouble(tf.getText(); if(i=0)tf.setText(String.valueOf(df.format(Math.sqrt(i); else tf.setText(负数不能开平方); else if(str.equals(log10) double i = Double.parseDouble(tf.getText(); if(i0) tf.setText(String.valueOf(df.forma

25、t(Math.log10(i); else tf.setText(负数不能求对数); else if(str.equals(%) tf.setText(df.format(Double.parseDouble(tf.getText()/100); else if(str.equals(ln) double i = Double.parseDouble(tf.getText(); if(i0) tf.setText(String.valueOf(df.format(Math.log(i); else tf.setText(负数不能求对数); else if(str.equals(sin) dou

26、ble i = Double.parseDouble(tf.getText(); tf.setText(String.valueOf(df.format(Math.sin(i); else if(str.equals(cos) double i = Double.parseDouble(tf.getText(); tf.setText(String.valueOf(df.format(Math.cos(i); else if(str.equals(tan) double i = Double.parseDouble(tf.getText(); tf.setText(String.valueOf

27、(df.format(Math.tan(i); else if(str.equals(N!) double i = Double.parseDouble(tf.getText(); if(i%2=0)|(i%2=1) int j = (int) i; int result = 1; for(int k = 1; k = j; k+) result*=k; tf.setText(String.valueOf(result); else tf.setText(无法进行阶乘); else if(str.equals(X2) double i = Double.parseDouble(tf.getText(); tf.setText(String.valueOf(df.format(i*i); else if(str.equals(X3) double i = Double.parseDouble(tf.getText(); tf.setText(String.valueOf(df.format(i*i*i); else if(str.equals(angle) double i = Double.parseDouble(tf.getText();

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

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