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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

JAVA课程设计报告心得体会计算器文本编辑器.docx

1、JAVA课程设计报告心得体会计算器文本编辑器用Java设计计算器calculator内容提要:在本文构造实现了一个计算器擦亮calculator,主要内容包括:calculator的功能需求分析;calculator的基本设计思路和类的划分;calculator的具体实现。关键字:Java、计算器calculator引言:设计实现一个Java应用程序的过程如下:(1) 功能需求分析;(2) 设计和类划分;(3) 代码编写实现。本文就按照这个步骤来实现计算器calculator的制作。正文:1. calculator功能需求分析作为计算器,至少应该具备以下几点功能:(1) 计算器要有GUI界面。

2、(2) 能运算小数,并且不会产生精度损失。(3) 用户可以输入所需计算的数值,可以进行加、减、乘、除四种最基本的运算和混合运算。(4) 允许正负数间的运算。(5) 可以求一个数值的平方及倒数,可以进行阶乘运算。(6) 有菜单栏选项。具体的功能需求和界面我们可以模仿微软公司出品的windowsXP中自带的计算器。如图一: 图一 windows XP 中的计算器界面图2. calculator基本设计思路和类划分基于第1节中提出对于calculator功能需求的分析,对这个应用程序设计划分类如下:(1) calculator:这个类的功能是实现一个框架(2) calculatorFrame:这个类

3、作为主类,实现主要功能:运算,按钮排布,菜单,颜色设置,文本显示3. calculator的具体实现3.1 calculator类的设计calculator用来定义一个计算器的框架1.主要方法下面以表格的形式列出calculator类至少应该具有的方法和功能描述(如表一所示)。表一 calculator类的主要方法方法 功能描述static void main (String args)calculator应用程序的入口,是主方法3.2 calculatorFrame类的设计 calculatorFrame类实现整体功能,包括窗体的初始化、各种用户事件监听和响应(菜单、运算、结果显示等等)。1

4、. 父类和主要接口设计calculator整体 窗口特性继承自JFrame类。为了对用户命令做出响应(如帮助菜单栏弹出窗口),calculatorFrame类必须能够监听到用户的命令,因此设计calculatorFrame类实现ActionListener接口。2. 主要方法下面以表格的形式列出calculatorFrame类至少应该具有的方法和功能描述(如表二所示)。表二 calculatorFrame类的主要方法方法功能描述void actionPerformed(ActionEvent e)重载ActionListener接口中的方法,用于对用户命令进行响应,用户命令包括“帮助”“版权”

5、“说明”以及各个按钮等3. 基本效果图二为calculator的基本效果图。4. 代码分析calculator.java代码如下:/calculator.java/*文件名:calculator.java*说明:calculatorFrame主类,实现主要功能*/导入AWT包import java.awt.*;import java.awt.event.*;/导入SWING包import javax.swing.*;import javax.swing.event.*; class calculator public static void main(String args) calculat

6、orFrame frame = new calculatorFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.show(); /主类calculatorFrameclass calculatorFrame extends JFrame implements ActionListener public calculatorFrame() /设置框架主题及大小setTitle(计算器); setSize(300,235); /将面板置于框架中 Container contentPane = getContent

7、Pane(); setResizable(false); /创建按钮面板 JPanel buttonPanel = new JPanel(); /创建数字键“1” b11=new JButton (1); /设置颜色 b11.setForeground(Color. BLUE); /创建事件监听器 b11.addActionListener(this); b12=new JButton (2); b12.setForeground(Color. BLUE); b12.addActionListener(this); b13=new JButton (3); b13.setForeground(

8、Color. BLUE); b13.addActionListener(this); b6=new JButton (4); b6.setForeground(Color. BLUE); b6.addActionListener(this); b7=new JButton (5); b7.setForeground(Color. BLUE); b7.addActionListener(this); b8=new JButton (6); b8.setForeground(Color. BLUE); b8.addActionListener(this); b1=new JButton (7);

9、b1.setForeground(Color. BLUE); b1.addActionListener(this); b2=new JButton (8); b2.setForeground(Color. BLUE); b2.addActionListener(this); b3=new JButton (9); b3.setForeground(Color. BLUE); b3.addActionListener(this); b16=new JButton (0); b16.setForeground(Color. BLUE); b16.addActionListener(this); b

10、17=new JButton (+/-); b17.setForeground(Color. BLUE); b17.addActionListener(this); b4=new JButton (+); b4.addActionListener(this); b9=new JButton (-); b9.addActionListener(this); b14=new JButton (*); b14.addActionListener(this); b19=new JButton (/); b19.addActionListener(this); b5=new JButton (1/x);

11、 b5.setForeground(Color. YELLOW); b5.addActionListener(this); b20=new JButton (=); b20.setForeground(Color. YELLOW); b20.addActionListener(this); /”.”显示不清晰,故采用“。”代替b18=new JButton (。);b18.setForeground(Color. BLUE); b18.addActionListener(this); b10=new JButton (x2); b10.setForeground(Color. YELLOW);

12、 b10.addActionListener(this); b15=new JButton (n!); b15.setForeground(Color. YELLOW); b15.addActionListener(this); buttonPanel.add(b1); buttonPanel.add(b2); buttonPanel.add(b3); buttonPanel.add(b4); buttonPanel.add(b5); buttonPanel.add(b6); buttonPanel.add(b7); buttonPanel.add(b8); buttonPanel.add(b

13、9); buttonPanel.add(b10); buttonPanel.add(b11); buttonPanel.add(b12); buttonPanel.add(b13); buttonPanel.add(b14); buttonPanel.add(b15); buttonPanel.add(b16); buttonPanel.add(b17); buttonPanel.add(b18); buttonPanel.add(b19); buttonPanel.add(b20); /对按钮面板1进行排版,四行五列 buttonPanel.setLayout(new GridLayout(

14、4,5); /建立容纳文本框的面板 JPanel textPanel = new JPanel(); addText = new JTextField(0 , 20); addText.addActionListener(this); /文本框从右端开始显示 addText.setHorizontalAlignment(JTextField.RIGHT); textPanel.add(addText); /创建按钮面板2 JPanel buttonPanel2=new JPanel(); b21=new JButton (DEL ); b21.addActionListener(this);

15、b21.setForeground(Color. RED); b22=new JButton (CE); b22.addActionListener(this); b22.setForeground(Color. RED); b23=new JButton (C); b23.addActionListener(this); b23.setForeground(Color. RED); buttonPanel2.add(b21); buttonPanel2.add(b22); buttonPanel2.add(b23); buttonPanel2.setLayout(new GridLayout

16、(1,5); /创建菜单栏,并将菜单栏加入到框架中 JMenuBar menuBar=new JMenuBar(); setJMenuBar(menuBar); /创建“帮助(H) ”菜单 JMenu helpMenu=new JMenu(帮助(H); helpMenu.setForeground(Color. BLUE); /设置菜单的快捷键 helpMenu.setMnemonic(H); menuBar.add(helpMenu); JMenuItem copyrightItem = new JMenuItem(版权, b); copyrightItem.addActionListene

17、r(this); JMenuItem explainItem=new JMenuItem(说明,a); explainItem.addActionListener(this); /将菜单项添加到“帮助”菜单中 helpMenu.add(copyrightItem); helpMenu.add(explainItem); /设置面板布局 contentPane.add(buttonPanel, BorderLayout.SOUTH); contentPane.add(buttonPanel2, BorderLayout.CENTER); contentPane.add(textPanel, Bo

18、rderLayout.NORTH); /设置用户点击菜单项和按钮时的响应动作 public void actionPerformed(ActionEvent e) if (e.getActionCommand()=版权) int selection=JOptionPane.showConfirmDialog( calculatorFrame.this, 制作人:20095409 金华日,20095403 章旭,20095397 李伏俊,版权, JOptionPane.DEFAULT_OPTION); if(e.getActionCommand()=说明) int selection=JOpti

19、onPane.showConfirmDialog( calculatorFrame.this, 此计算器可进行多种常规运算,欢迎大家使用。,帮助, JOptionPane.DEFAULT_OPTION); if(addText.getText().equals(0) addText.setText( ); if(e.getSource()=b16) c+=0; addText.setText(+c); if(e.getSource()=b11) c+=1; addText.setText(+c); if(e.getSource()=b12) c+=2; addText.setText(+c);

20、 if(e.getSource()=b13) c+=3; addText.setText(+c); if(e.getSource()=b6) c+=4; addText.setText(+c); if(e.getSource()=b7) c+=5; addText.setText(+c); if(e.getSource()=b8) c+=6; addText.setText(+c); if(e.getSource()=b1) c+=7; addText.setText(+c); if(e.getSource()=b2) c+=8; addText.setText(+c); if(e.getSo

21、urce()=b3) c+=9; addText.setText(+c); if(e.getSource()=b18) boolean clickable=true; for (int i = 0; i addText.getText().length(); i+) if (. = addText.getText().charAt(i) clickable=false; break; if(clickable) c+=.; addText.setText(c); /平方 if(e.getSource()=b10) nu =Double.parseDouble(addText.getText()

22、; num=nu*nu; addText.setText(String.valueOf(num); c=; /倒数 if(e.getSource()=b5) nu =Double.parseDouble(addText.getText(); if(addText.getText().charAt(0)=0&addText.getText().length()=1) addText.setText(除数不能为0); else num=1/nu; addText.setText(String.valueOf(num); c=; /阶乘 if(e.getSource()=b15) c=;num=1;

23、 nu =Double.parseDouble(addText.getText(); for (int n=1;n=nu;n+) num=num*n; addText.setText(String.valueOf(num); /响应“+/-”按钮 if(e.getSource()=b17) String s=addText.getText(); if(addText.getText().charAt(0)=-) addText .setText(); for (int i=1;is.length();i+) char q=s.charAt(i); addText.setText(addText

24、.getText()+q); else addText.setText(-+s); /将文本框清零 if(e.getActionCommand()=CE) addText.setText(0); c=; if(e.getActionCommand()=C) addText.setText(0); c=; /删除文本框中的最后一位数 if (e.getSource()=b21) String g=addText.getText(); addText.setText(); for (int i=0;ig.length()-1;i+) char c=g.charAt(i); addText.setT

25、ext(addText.getText()+ c); /响应“+” “-” “*” “/” 按钮 if(e.getSource()=b4) f=+; nu =Double.parseDouble(addText.getText(); c=; if(e.getSource()=b9) f=-; nu =Double.parseDouble(addText.getText(); c=; if(e.getSource()=b14) f=*; nu =Double.parseDouble(addText.getText(); c=; if(e.getSource()=b19) f=/; nu =Dou

26、ble.parseDouble(addText.getText(); c=; /进行运算,并将结果显示在文本框内 if(e.getSource()=b20) nu2 =Double.parseDouble(addText.getText(); if(f=+) num=nu+nu2; addText.setText(String.valueOf(num); c=; if(f=-) num=nu-nu2; addText.setText(String.valueOf(num); c=; if(f=*) num=nu*nu2; addText.setText(String.valueOf(num);

27、 c=; if(f=/) num=nu/nu2; addText.setText(String.valueOf(num); c=; /定义各个变量类型 public JTextField addText; public JButton b1; public JButton b2; public JButton b3; public JButton b4; public JButton b5; public JButton b6; public JButton b7; public JButton b8; public JButton b9; public JButton b10; public

28、 JButton b11; public JButton b12; public JButton b13; public JButton b14; public JButton b15; public JButton b16; public JButton b17; public JButton b18; public JButton b19; public JButton b20; public JButton b21; public JButton b22; public JButton b23; public double num,nu,nu2; public char f; String c=; 5. 心得体会Java监听器是Java功能实现的重要组成部分

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2