最新JAVA课程设计报告-心得体会——计算器、文本编辑器.doc
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《最新JAVA课程设计报告-心得体会——计算器、文本编辑器.doc》由会员分享,可在线阅读,更多相关《最新JAVA课程设计报告-心得体会——计算器、文本编辑器.doc(100页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Four short words sum up what has lifted most successful individuals above the crowd: a little bit more.-author-dateJAVA课程设计报告-心得体会计算器、文本编辑器JAVA课程设计报告-心得体会计算器、文本编辑器用Java设计计算器calculator内容提要:在本文构造实现了一个计算器擦亮calculator,主要内容包括:calculator的功能需求分析;calculator的基本设计思路和类的划分;calculator的具体实现。关键字:Java、计算器calculator
2、引言:设计实现一个Java应用程序的过程如下:(1) 功能需求分析;(2) 设计和类划分;(3) 代码编写实现。本文就按照这个步骤来实现计算器calculator的制作。正文:1. calculator功能需求分析作为计算器,至少应该具备以下几点功能:(1) 计算器要有GUI界面。(2) 能运算小数,并且不会产生精度损失。(3) 用户可以输入所需计算的数值,可以进行加、减、乘、除四种最基本的运算和混合运算。(4) 允许正负数间的运算。(5) 可以求一个数值的平方及倒数,可以进行阶乘运算。(6) 有菜单栏选项。具体的功能需求和界面我们可以模仿微软公司出品的windowsXP中自带的计算器。如图一
3、: 图一 windows XP 中的计算器界面图2. calculator基本设计思路和类划分基于第1节中提出对于calculator功能需求的分析,对这个应用程序设计划分类如下:(1) calculator:这个类的功能是实现一个框架(2) calculatorFrame:这个类作为主类,实现主要功能:运算,按钮排布,菜单,颜色设置,文本显示3. calculator的具体实现3.1 calculator类的设计calculator用来定义一个计算器的框架1.主要方法下面以表格的形式列出calculator类至少应该具有的方法和功能描述(如表一所示)。表一 calculator类的主要方法方
4、法 功能描述static void main (String args)calculator应用程序的入口,是主方法3.2 calculatorFrame类的设计 calculatorFrame类实现整体功能,包括窗体的初始化、各种用户事件监听和响应(菜单、运算、结果显示等等)。1. 父类和主要接口设计calculator整体 窗口特性继承自JFrame类。为了对用户命令做出响应(如帮助菜单栏弹出窗口),calculatorFrame类必须能够监听到用户的命令,因此设计calculatorFrame类实现ActionListener接口。2. 主要方法下面以表格的形式列出calculatorF
5、rame类至少应该具有的方法和功能描述(如表二所示)。表二 calculatorFrame类的主要方法方法功能描述void actionPerformed(ActionEvent e)重载ActionListener接口中的方法,用于对用户命令进行响应,用户命令包括“帮助”“版权”“说明”以及各个按钮等3. 基本效果图二为calculator的基本效果图。4. 代码分析calculator.java代码如下:/calculator.java/*文件名:calculator.java*说明:calculatorFrame主类,实现主要功能*/导入AWT包import java.awt.*;imp
6、ort java.awt.event.*;/导入SWING包import javax.swing.*;import javax.swing.event.*; class calculator public static void main(String args) calculatorFrame frame = new calculatorFrame();frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.show();/主类calculatorFrameclass calculatorFrame extends JFrame
7、implements ActionListener public calculatorFrame()/设置框架主题及大小setTitle(计算器);setSize(300,235); /将面板置于框架中Container contentPane = getContentPane();setResizable(false); /创建按钮面板 JPanel buttonPanel = new JPanel(); /创建数字键“1” b11=new JButton (1); /设置颜色 b11.setForeground(Color. BLUE); /创建事件监听器 b11.addActionLis
8、tener(this); b12=new JButton (2); b12.setForeground(Color. BLUE); b12.addActionListener(this); b13=new JButton (3); b13.setForeground(Color. BLUE); b13.addActionListener(this); b6=new JButton (4); b6.setForeground(Color. BLUE); b6.addActionListener(this); b7=new JButton (5); b7.setForeground(Color.
9、BLUE); b7.addActionListener(this); b8=new JButton (6); b8.setForeground(Color. BLUE); b8.addActionListener(this); b1=new JButton (7); b1.setForeground(Color. BLUE); b1.addActionListener(this); b2=new JButton (8); b2.setForeground(Color. BLUE); b2.addActionListener(this); b3=new JButton (9); b3.setFo
10、reground(Color. BLUE); b3.addActionListener(this); b16=new JButton (0); b16.setForeground(Color. BLUE); b16.addActionListener(this); b17=new JButton (+/-); b17.setForeground(Color. BLUE); b17.addActionListener(this); b4=new JButton (+); b4.addActionListener(this); b9=new JButton (-); b9.addActionLis
11、tener(this); b14=new JButton (*); b14.addActionListener(this); b19=new JButton (/); b19.addActionListener(this); b5=new JButton (1/x); b5.setForeground(Color. YELLOW); b5.addActionListener(this); b20=new JButton (=); b20.setForeground(Color. YELLOW); b20.addActionListener(this); /”.”显示不清晰,故采用“。”代替b1
12、8=new JButton (。);b18.setForeground(Color. BLUE); b18.addActionListener(this); b10=new JButton (x2); b10.setForeground(Color. YELLOW); b10.addActionListener(this); b15=new JButton (n!); b15.setForeground(Color. YELLOW); b15.addActionListener(this); buttonPanel.add(b1); buttonPanel.add(b2); buttonPan
13、el.add(b3); buttonPanel.add(b4); buttonPanel.add(b5); buttonPanel.add(b6); buttonPanel.add(b7); buttonPanel.add(b8); buttonPanel.add(b9); buttonPanel.add(b10); buttonPanel.add(b11); buttonPanel.add(b12); buttonPanel.add(b13); buttonPanel.add(b14); buttonPanel.add(b15); buttonPanel.add(b16); buttonPa
14、nel.add(b17); buttonPanel.add(b18); buttonPanel.add(b19); buttonPanel.add(b20); /对按钮面板1进行排版,四行五列 buttonPanel.setLayout(new GridLayout(4,5); /建立容纳文本框的面板JPanel textPanel = new JPanel();addText = new JTextField(0 , 20);addText.addActionListener(this); /文本框从右端开始显示addText.setHorizontalAlignment(JTextFiel
15、d.RIGHT);textPanel.add(addText); /创建按钮面板2 JPanel buttonPanel2=new JPanel(); b21=new JButton (DEL ); b21.addActionListener(this);b21.setForeground(Color. RED);b22=new JButton (CE);b22.addActionListener(this);b22.setForeground(Color. RED);b23=new JButton (C);b23.addActionListener(this);b23.setForegrou
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 最新 JAVA 课程设计 报告 心得体会 计算器 文本 编辑器
![提示](https://www.taowenge.com/images/bang_tan.gif)
限制150内