欢迎来到装配图网! | 帮助中心 装配图网zhuangpeitu.com!
装配图网
ImageVerifierCode 换一换
首页 装配图网 > 资源分类 > DOC文档下载
 

简单图形界面计算器的设计_java课程设计报告

  • 资源ID:37466908       资源大小:345.50KB        全文页数:32页
  • 资源格式: DOC        下载积分:15积分
快捷下载 游客一键下载
会员登录下载
微信登录下载
三方登录下载: 微信开放平台登录 支付宝登录   QQ登录   微博登录  
二维码
微信扫一扫登录
下载资源需要15积分
邮箱/手机:
温馨提示:
用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)
支付方式: 支付宝    微信支付   
验证码:   换一换

 
账号:
密码:
验证码:   换一换
  忘记密码?
    
友情提示
2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

简单图形界面计算器的设计_java课程设计报告

Java 课程设计简单图形界面计算器的设计课程名称 Java程序设计 选题名称 简单图形界面计算器的设计 专 业 班 级 姓 名 学 号 指导教师 简单图形界面计算器的设计一、设计任务与目标本次java程序设计我的设计任务是设计一个图形界面(GUI)的计算器应用程序并且能够完成简单的算术运算。本次任务的基本要求是这个计算器应用程序可以完成十进制的加、减、乘、除、求倒、取余、开方运算,且有小数点、正负号、退格和清零功能。而我要在此基础上添加一项千位符分隔符的功能,即以三位为一级,在输入的一串数字中每三位加入一个逗号,这项功能国际通用,并已经成为惯例,会计记账都用这种方法便于账目核算与管理。GUI计算器设计的具体目标:1. 完成十进制的加、减、乘、除、求倒、取余和开方运算;2. 有小数点和正负号加入运算;3. 有退格、复位和清零的功能;4. 有千位符分隔符的功能,即在输入的一串数字中每三位加入一个逗号。二、方案设计与论证1.设计目标的总体分析(1)设计目标的需求分析:计算器是现在一个普遍应用的工具,能够解决许多人工所无法计算的数据,节省大量宝贵的时间。(2)设计目标的功能分析:实现计算器系统的功能,主要有两个功能模块:输入 和 输出。(3)设计原则:基于计算器系统要具有适用性广、操作简便等特点,本系统预计要达到以下几个目标:满足以上的基本功能要求;能够在常见的计算机及其操作系统上运行。2.设计的基本思路利用GUI的界面设计,将整个大设计分为三块,分别是数据的输入,运算符功能符的控制和数据的输入输出显示。利用Swing控件,数据的输入由09这10个按钮来表示,用“+”、“-”、“*”、“/”、“1/x”、“%”、“sqrt”这7个按钮来表示加、减、乘、除、求倒、取余、开方运算,用“.”和“”这2个按钮来表示小数点和正负号,用“Back”、“CE”和“C”这3个按钮来表示退格、复位和清零的功能,数据的输入输出显示由文本字段来表示。将计算器的总体界面设计好后,再将代码分别写入不同的按钮的源程序中。我要完成的一项改进,即添加一个拥有千位符分隔符功能的按钮,按下这个按钮能够在输入的一串数字中每三位加入一个逗号并且显示出来。我要在之前的界面设计的基础上多添加一个按钮“$”来表示千位符分隔符,并且将功能代码写入这个按钮的源程序中。三、程序流程图,程序清单与调用关系1. 程序流程图:2. 程序清单09数据的输入private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) / TODO add your handling code here: if(flag = false&&!jTextField1.getText().equals("0") jTextField1.setText(jTextField1.getText()+"1"); else jTextField1.setText("1"); flag = false; “+”号的控制private void jButton19ActionPerformed(java.awt.event.ActionEvent evt) / TODO add your handling code here: /加号 d1 = Double.parseDouble(jTextField1.getText(); flag = true; op = "+" “-”号的控制private void jButton18ActionPerformed(java.awt.event.ActionEvent evt) / TODO add your handling code here: /减号 d1 = Double.parseDouble(jTextField1.getText(); flag = true; op = "-" “*”号的控制private void jButton17ActionPerformed(java.awt.event.ActionEvent evt) / TODO add your handling code here: /乘号 d1 = Double.parseDouble(jTextField1.getText(); flag = true; op = "*" “/”号的控制 private void jButton16ActionPerformed(java.awt.event.ActionEvent evt) / TODO add your handling code here: /除号 d1 = Double.parseDouble(jTextField1.getText(); flag = true; op = "/" “%”取余运算private void jButton24ActionPerformed(java.awt.event.ActionEvent evt) / TODO add your handling code here: /求余 d1 = Double.parseDouble(jTextField1.getText(); flag = true; op = "%" “.”号的加入private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) / TODO add your handling code here: /点号 if(jTextField1.getText().equals("")|flag = true) jTextField1.setText("0."); else jTextField1.setText(jTextField1.getText()+"."); flag = false; “”号的加入private void jButton15ActionPerformed(java.awt.event.ActionEvent evt) / TODO add your handling code here: /正负号 double d = Double.parseDouble(jTextField1.getText(); d = 0 - d; jTextField1.setText(""+d); “sqrt”开方运算private void jButton21ActionPerformed(java.awt.event.ActionEvent evt) / TODO add your handling code here: /开方 double d = Double.parseDouble(jTextField1.getText(); jTextField1.setText(""+Math.sqrt(d); “1/x”求倒数运算private void jButton22ActionPerformed(java.awt.event.ActionEvent evt) / TODO add your handling code here: /求倒数 double d = Double.parseDouble(jTextField1.getText(); if(d=0) jTextField1.setText("0"); else jTextField1.setText(""+(1/d); “=”等号运算private void jButton23ActionPerformed(java.awt.event.ActionEvent evt) / TODO add your handling code here: if(op.equals("") return; d2 = Double.parseDouble(jTextField1.getText(); double result = 0; if(op.equals("+") result = d1 + d2; else if(op.equals("-") result = d1 - d2; else if(op.equals("*") result = d1 * d2; else if(op.equals("/") result = d1 / d2; if(d2 = 0) result = 0; else if(op.equals("%") result = d1 % d2; if(d2 = 0) result = 0; jTextField1.setText(""+result); flag = true; “Back”退格运算private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) / TODO add your handling code here: /if语句判定当前字符串是否为空,若不为空,则将字符串长度减1之后,再赋值给原字符串;否则,将0复制给原字符串。 String s = jTextField1.getText(); if(!s.equals("") s = s.substring(0,s.length()-1); if(s.equals("") s = "0" jTextField1.setText(s); “CE”复位运算private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) / TODO add your handling code here: /复位操作 jTextField1.setText("0"); d1 = 0; d2 = 0; op = "" flag = false; “C”清零运算private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) / TODO add your handling code here: /清零操作 jTextField1.setText("0"); “$”千位符分隔符运算private void jButton20ActionPerformed(java.awt.event.ActionEvent evt) / TODO add your handling code here: /千位符分隔符 d1 = Double.parseDouble(jTextField1.getText(); flag = true; op = "$" DecimalFormat f = new DecimalFormat(",#"); jTextField1.setText(""+f.format(d1); 3. 程序的调用关系图NewJFrameBackCEC=$09+-*/%1/xsqrt.四、全部源程序清单/* Calculator.java GUI简单计算器 */package javacalculator;/* * * author */import java.awt.datatransfer.*;import java.text.DecimalFormat;public class NewJFrame extends javax.swing.JFrame /* * Creates new form NewJFrame */ public NewJFrame() initComponents(); flag = false; d1 = 0; d2 = 0; op = "" jTextField1.setText("0"); clipboard = getToolkit().getSystemClipboard(); private Clipboard clipboard; private boolean flag; private double d1; private double d2; private String op; SuppressWarnings("unchecked") / <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() jPanel1 = new javax.swing.JPanel(); jPanel2 = new javax.swing.JPanel(); jButton4 = new javax.swing.JButton(); jButton5 = new javax.swing.JButton(); jButton6 = new javax.swing.JButton(); jButton7 = new javax.swing.JButton(); jButton8 = new javax.swing.JButton(); jButton9 = new javax.swing.JButton(); jButton10 = new javax.swing.JButton(); jButton11 = new javax.swing.JButton(); jButton12 = new javax.swing.JButton(); jButton13 = new javax.swing.JButton(); jButton14 = new javax.swing.JButton(); jButton15 = new javax.swing.JButton(); jButton16 = new javax.swing.JButton(); jButton17 = new javax.swing.JButton(); jButton18 = new javax.swing.JButton(); jButton19 = new javax.swing.JButton(); jButton20 = new javax.swing.JButton(); jButton21 = new javax.swing.JButton(); jButton22 = new javax.swing.JButton(); jButton23 = new javax.swing.JButton(); jButton24 = new javax.swing.JButton(); jTextField1 = new javax.swing.JTextField(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jButton4.setText("7"); jButton4.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton4ActionPerformed(evt); ); jButton5.setText("8"); jButton5.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton5ActionPerformed(evt); ); jButton6.setText("9"); jButton6.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton6ActionPerformed(evt); ); jButton7.setText("4"); jButton7.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton7ActionPerformed(evt); ); jButton8.setText("5"); jButton8.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton8ActionPerformed(evt); ); jButton9.setText("6"); jButton9.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton9ActionPerformed(evt); ); jButton10.setText("1"); jButton10.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton10ActionPerformed(evt); ); jButton11.setText("2"); jButton11.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton11ActionPerformed(evt); ); jButton12.setText("3"); jButton12.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton12ActionPerformed(evt); ); jButton13.setText("0"); jButton13.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton13ActionPerformed(evt); ); jButton14.setText("."); jButton14.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton14ActionPerformed(evt); ); jButton15.setText(""); jButton15.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton15ActionPerformed(evt); ); jButton16.setText("/"); jButton16.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton16ActionPerformed(evt); ); jButton17.setText("*"); jButton17.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton17ActionPerformed(evt); ); jButton18.setText("-"); jButton18.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton18ActionPerformed(evt); ); jButton19.setText("+"); jButton19.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton19ActionPerformed(evt); ); jButton20.setText("$"); jButton20.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton20ActionPerformed(evt); ); jButton21.setText("sqrt"); jButton21.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton21ActionPerformed(evt); ); jButton22.setText("1/x"); jButton22.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton22ActionPerformed(evt); ); jButton23.setText("="); jButton23.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton23ActionPerformed(evt); ); jButton24.setText("%"); jButton24.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent evt) jButton24ActionPerformed(evt); ); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addGap(53, 53, 53) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jButton20, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addGroup(jPanel2Layout.createSequentialGroup() .addComponent(jButton13, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton15, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton14, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jButton19) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton23, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup() .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup() .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup() .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(jButton10, javax.swing.GroupLayout.DEFAULT_SIZE, 50, Short.MAX_VALUE) .addComponent(jButton7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup() .addComponent(jButton8, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton9, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup() .addComponent(jButton11, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton12, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(jPanel2Layout.createSequentialGroup() .addComponent(jButton17) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton21, javax.swing.GroupLayout.PREFERRED_SIZE, 70, java

注意事项

本文(简单图形界面计算器的设计_java课程设计报告)为本站会员(1666****666)主动上传,装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知装配图网(点击联系客服),我们立即给予删除!

温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!