Java计算器课程设计报告---模拟科学计算器

上传人:lizhe****0001 文档编号:31226320 上传时间:2018-02-06 格式:DOC 页数:16 大小:217KB
返回 下载 相关 举报
Java计算器课程设计报告---模拟科学计算器_第1页
第1页 / 共16页
Java计算器课程设计报告---模拟科学计算器_第2页
第2页 / 共16页
Java计算器课程设计报告---模拟科学计算器_第3页
第3页 / 共16页
Java计算器课程设计报告---模拟科学计算器_第4页
第4页 / 共16页
Java计算器课程设计报告---模拟科学计算器_第5页
第5页 / 共16页
点击查看更多>>
资源描述

《Java计算器课程设计报告---模拟科学计算器》由会员分享,可在线阅读,更多相关《Java计算器课程设计报告---模拟科学计算器(16页珍藏版)》请在金锄头文库上搜索。

1、高级编程技术课程设计模拟科学计算器一.概述1.程序具备的功能:(1)使用图形用户界面:一个文本框;0-9 数字按钮;加、减、乘、除运算符;“等于”符号;复位按钮;(2)完成整数、实数的四则运算(加、减、乘、除)以及三角函数的运算等等;(3)通过按钮点击实现数据的复位(清零) ;(4)实数运算中小数位的精度一致。实现要点:添加相关组件并进行按钮事件处理。要求提交源程序。2课程设计的主要设计思想对于此计算器程序,首先要设计其 GUI 界面,总体界面有一个文本,总体界面用布局管理器布局。布局设计好后再添加按钮事件。对于此程序要考虑到点击加、减、乘、除按钮时是否有点击数字按钮,如果是第一次点击数字按钮

2、或者是点击数字按钮前点击了加、减、乘、除按钮则直接把数字按钮的数值设置到文本框中,否则则应把文本框中的内容加上你所点击按钮的数值设置到文本框中。在进行加、减、乘、除计算时要把点击加、减、乘、除按钮之前的数值保存下来,运算时是这个被保存下来的数值和文本框中的数值加、减、乘、除以及三角函数等一系列的运算。二.课程设计思路1.界面设计2界面设计要求用 GUI,界面设计中有用到 swing 组件的 TextField 和Button,用到 awt 中的 BorderLayout 和 GridLayout 布局管理方式,其图形界面如下:2.功能介绍这是计算器中的一种:简单计算器,本项目用到了 Java

3、中的 GUI 界面和swing 组件以及 awt 布局,所以简单易用,它能完成如下的几个小功能:点击按钮中的数字键和运算符键就能进行简单的加、乘、乘、除求模四则运算 ;还能通过用户自己在文本框中输入数字,进行简单运算 ;如果输入有误时可以按 Clear 撤销后重新输入新数据 。三.设计过程以及源代码程序流程图如下:3UML 图如下:45附录源程序:import java.awt.*;import java.awt.event.*;import java.text.DecimalFormat;import javax.swing.*;public class Calucator extends

4、JFrame private JTextField tf;private JPanel panel1, panel2, panel3, panel4;private JMenuBar myBar;private JMenu menu1, menu2, menu3;private JMenuItem editItem1, editItem2, help1, help2, help3;private JRadioButtonMenuItem seeItem1, seeItem2;/单选框private JCheckBoxMenuItem seeItem3;/复选框private ButtonGro

5、up bgb;private String back;private boolean IfResult = true, flag = false;private String oper = =;private double result = 0;private Num numActionListener;private DecimalFormat df;public Calucator()super(科学计算器);/设置标题栏df = new DecimalFormat(#.#);/保留四位小数this.setLayout(new BorderLayout(10, 5);panel1 = ne

6、w JPanel(new GridLayout(1, 3, 10, 10);panel2 = new JPanel(new GridLayout(5, 6, 5, 5);/5行 6列panel3 = new JPanel(new GridLayout(5, 1, 5, 5);panel4 = new JPanel(new BorderLayout(5, 5);/* 菜单栏*/myBar = new JMenuBar();menu1 = new JMenu(编辑(E);menu2 = new JMenu(查看(V);menu3 = new JMenu(帮助(H);menu1.setFont(ne

7、w Font(宋体, Font.PLAIN, 12);menu2.setFont(new Font(宋体, Font.PLAIN, 12);6menu3.setFont(new Font(宋体, Font.PLAIN, 12);/* 编辑栏*/editItem1 = new JMenuItem(复制(C) Ctrl+C);editItem2 = new JMenuItem(粘贴(P) Ctrl+V);editItem1.setFont(new Font(宋体,Font.PLAIN,12);editItem2.setFont(new Font(宋体,Font.PLAIN,12);/* 查看栏*/

8、seeItem1 = new JRadioButtonMenuItem(科学型(T);seeItem2 = new JRadioButtonMenuItem(标准型(S);seeItem3 = new JCheckBoxMenuItem(数字分组(I);seeItem1.setFont(new Font(宋体,Font.PLAIN,12);seeItem2.setFont(new Font(宋体,Font.PLAIN,12);seeItem3.setFont(new Font(宋体,Font.PLAIN,12);/* 帮助栏*/help1 = new JMenuItem(帮助主题(H);hel

9、p2 = new JMenuItem(关于计算器(A);help1.setFont(new Font(宋体,Font.PLAIN,12);help2.setFont(new Font(宋体,Font.PLAIN,12);bgb = new ButtonGroup();/选项组menu1.add(editItem1);menu1.add(editItem2);menu2.add(seeItem1);menu2.add(seeItem2);menu2.addSeparator();/添加一条分割线menu2.add(seeItem3);menu3.add(help1);menu3.addSepar

10、ator();/添加一条分割线menu3.add(help2);7myBar.add(menu1);myBar.add(menu2);myBar.add(menu3);this.setJMenuBar(myBar);numActionListener = new Num();/实现数字监听/* 文本域,即为计算器的屏幕显示区域*/tf = new JTextField();tf.setEditable(false);/文本区域不可编辑tf.setBackground(Color.white);/文本区域的背景色tf.setHorizontalAlignment(JTextField.RIGHT

11、);/文字右对齐tf.setText(0);tf.setBorder(BorderFactory.createLoweredBevelBorder();init();/对计算器进行初始化/* 初始化操作* 添加按钮*/private void init()addButton(panel1, Backspace, new Clear(), Color.red);addButton(panel1, CE, new Clear(), Color.red);addButton(panel1, C, new Clear(), Color.red);addButton(panel2, 1/x, new S

12、igns(), Color.magenta);addButton(panel2, log, new Signs(), Color.magenta);addButton(panel2, 7, numActionListener, Color.blue);addButton(panel2, 8, numActionListener, Color.blue);addButton(panel2, 9, numActionListener, Color.blue);addButton(panel2, , new Signs(), Color.red);addButton(panel2, n!, new

13、Signs(), Color.magenta);addButton(panel2, sqrt, new Signs(), Color.magenta);addButton(panel2, 4, numActionListener, Color.blue);addButton(panel2, 5, numActionListener, Color.blue);addButton(panel2, 6, numActionListener, Color.blue);addButton(panel2, , new Signs(), Color.red);8addButton(panel2, sin,

14、new Signs(), Color.magenta);addButton(panel2, x2, new Signs(), Color.magenta);addButton(panel2, 1, numActionListener, Color.blue);addButton(panel2, 2, numActionListener, Color.blue);addButton(panel2, 3, numActionListener, Color.blue);addButton(panel2, -, new Signs(), Color.red);addButton(panel2, cos

15、, new Signs(), Color.magenta);addButton(panel2, x3, new Signs(), Color.magenta);addButton(panel2, 0, numActionListener, Color.blue);addButton(panel2, -/+, new Clear(), Color.blue);addButton(panel2, ., new Dot(), Color.blue);addButton(panel2, +, new Signs(), Color.red);addButton(panel2, tan, new Signs(), Color.magenta);addButton(panel2, %, new Signs(), Color.magenta);addButton(panel2, , numActionListener, Color.orange);addButton(panel2, e, numActionListener, Color.orange);addButton(panel2, , new Signs(), Color.orange);addButton(panel2, =, new Signs(), Color.red);JButton btns = new

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 学术论文 > 毕业论文

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号