欢迎来到三一办公! | 帮助中心 三一办公31ppt.com(应用文档模板下载平台)
三一办公
全部分类
  • 办公文档>
  • PPT模板>
  • 建筑/施工/环境>
  • 毕业设计>
  • 工程图纸>
  • 教育教学>
  • 素材源码>
  • 生活休闲>
  • 临时分类>
  • ImageVerifierCode 换一换
    首页 三一办公 > 资源分类 > DOC文档下载  

    JAVA课程设计模拟科学计算器 .doc

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

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

    JAVA课程设计模拟科学计算器 .doc

    课程设计报告课程:模拟科学计算器 学号: 姓名: 班级: 教师: 时间:10.12.1011.01.12 计算机科学与技术系课程设计指导书姓 名学 号班 级课程名称JAVA课程性质专业必修课设计时间2010年12 月10日2011年01月12日设计名称模拟科学计算器设计目的巩固所学理论知识,提高程序设计能力的重要实践环节。综合应用Java基础知识和基本方法。设计要求界面模拟Windows中的计算器程序。实现基本数学运算、函数等功能:加、减、乘、除、阶乘、正弦、余弦和指数运算。实现要点:添加相关组件并进行按钮事件处理。要求提交Application和Applet两个版本的程序。设计思路与设计过程设计Application和Applet两个版本的程序,对Application运用继承JFrame设计,类的设计构造方法利用等。而Applet则继承Applet,在浏览器上运行。Application过程:1. 菜单栏设计.2. 文本域,即为计算器的屏幕显示区域3. 初始化操作4. 统一设置按钮的的使用方式5. 计算器的基础操作(+ - × ÷)6. 运算符号的事件监听7. 清除按钮的事件监听8. 数字输入的事件监听9. 小数点的事件监听10. main方法Applet过程:1. init()方法:完成初始化操作;2. 事件统一监听;3. 科学计算;4. 建立Calucator.html;5. 浏览器运行;计划与进度12.10-12.13 复习Java程序开发的相关操作,了解“计算器相关知识”;12.14-12.17 熟悉题目并理解,及找寻相关资料;12.18-12.20 根据题目要求进行需求分析设计;12.21-12.25 对Application进行总体程序设计;12.26-12.30 对Applet进行相关各功能的程序设计;12.31-01.05 对程序进行细节完善;01.06-01.10 进行调试运行并完成资料归档。任课教师意 见备 注设计名称:模拟科学计算器日期:2010年01月05日 设计内容:Application和Applet两个版本的程序,实现基本数学运算、函数等功能:加、减、乘、除、阶乘、正弦、余弦和指数运算。对Application运用继承JFrame设计,类的设计构造方法利用等。而Applet则继承Applet,在浏览器上运行。设计目的与要求:界面模拟Windows中的计算器程序。实现基本数学运算、函数等功能:加、减、乘、除、阶乘、正弦、余弦和指数运算。实现要点:添加相关组件并进行按钮事件处理。要求提交Application和Applet两个版本的程序。设计环境或器材、原理与说明:设计环境或器材: 硬件:计算机 软件:MyEclipse 集成开发环境 Java JCreator Pro;设计原理说明:运用Application和Applet两个版本的程序。设计过程(步骤)或程序代码(可以加页):Application程序代码:import java.awt.*;import java.awt.event.*;import java.text.DecimalFormat;import javax.swing.*;public class Calucator extends 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 ButtonGroup 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 = new 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(new Font("宋体", Font.PLAIN, 12);menu2.setFont(new Font("宋体", Font.PLAIN, 12);menu3.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);/* * 查看栏 */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)");help2 = 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.addSeparator();/添加一条分割线menu3.add(help2);myBar.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);/文字右对齐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 Signs(), 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 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);addButton(panel2, "sin", 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", 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 JButton("计算器");btns.setBorder(BorderFactory.createLoweredBevelBorder();btns.setEnabled(false);/按钮不可操作btns.setPreferredSize(new Dimension(20, 20);panel3.add(btns);/加入按钮addButton(panel3, "MC", null, Color.red);addButton(panel3, "MR", null, Color.red);addButton(panel3, "MS", null, Color.red);addButton(panel3, "M+", null, Color.red);panel4.add(panel1, BorderLayout.NORTH);panel4.add(panel2, BorderLayout.CENTER);this.add(tf, BorderLayout.NORTH);this.add(panel3, BorderLayout.WEST);this.add(panel4);pack();this.setResizable(false);/窗口不可改变大小this.setLocation(300, 200);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);/* * 统一设置按钮的的使用方式 * param panel * param name * param action * param color */private void addButton(JPanel panel, String name, ActionListener action, Color color)JButton bt = new JButton(name);panel.add(bt);/在面板上增加按钮bt.setForeground(color);/设置前景(字体)颜色bt.addActionListener(action);/增加监听事件/* * 计算器的基础操作(+ - × ÷) * param x */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 ActionListenerpublic void actionPerformed(ActionEvent e) /* * 用ActionEvent对象的getActionCommand()方法 * 取得与引发事件对象相关的字符串 */String str = e.getActionCommand();/* sqrt求平方根 */if(str.equals("sqrt")double i = Double.parseDouble(tf.getText();if(i>=0)/* * String.valueOf() 转换为字符串 * df.format() 按要求保留四位小数 * Math.sqrt() 求算数平方根 */tf.setText(String.valueOf(df.format(Math.sqrt(i);elsetf.setText("负数不能开平方根");/* log求常用对数 */else if(str.equals("log")double i = Double.parseDouble(tf.getText();if(i>0)tf.setText(String.valueOf(df.format(Math.log(i);elsetf.setText("负数不能求对数");/* %求百分比 */else if(str.equals("%")tf.setText(df.format(Double.parseDouble(tf.getText() / 100);/* 1/x求倒数 */else if(str.equals("1/x")if(Double.parseDouble(tf.getText() = 0)tf.setText("除数不能为零");elsetf.setText(df.format(1 / Double.parseDouble(tf.getText();/* sin求正弦函数 */else if(str.equals("sin")double i = Double.parseDouble(tf.getText();tf.setText(String.valueOf(df.format(Math.sin(i);/* cos求余弦函数 */else if(str.equals("cos")double i = Double.parseDouble(tf.getText();tf.setText(String.valueOf(df.format(Math.cos(i);/* tan求正切函数 */else if(str.equals("tan")double i = Double.parseDouble(tf.getText();tf.setText(String.valueOf(df.format(Math.tan(i);/* n!求阶乘 */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);elsetf.setText("无法进行阶乘");/* x2求平方 */else if(str.equals("x2")double i = Double.parseDouble(tf.getText();tf.setText(String.valueOf(df.format(i*i);/* x3求立方 */else if(str.equals("x3")double i = Double.parseDouble(tf.getText();tf.setText(String.valueOf(df.format(i*i*i);/* 角度转换 */* * 将角度值转换成弧度值,方便三角函数的计算 */else if(str.equals("")double i = Double.parseDouble(tf.getText();tf.setText(String.valueOf(i/180*Math.PI);elseif(flag)IfResult = false;if(IfResult)oper = str;else getResult(Double.parseDouble(tf.getText();oper = str;IfResult = true;/* * 清除按钮的事件监听 */class Clear implements ActionListenerpublic void actionPerformed(ActionEvent e) /* * 用ActionEvent对象的getActionCommand()方法 * 取得与引发事件对象相关的字符串 */String str = e.getActionCommand();if(str = "C")tf.setText("0");IfResult = true;result = 0;else if(str = "-/+")double i = 0 - Double.parseDouble(tf.getText().trim();tf.setText(df.format(i);else if(str = "Backspace")if(Double.parseDouble(tf.getText() > 0)if(tf.getText().length() > 1)tf.setText(tf.getText().substring(0, tf.getText().length() - 1);/使用退格删除最后一位字符elsetf.setText("0");IfResult = true;elseif(tf.getText().length() > 2)tf.setText(tf.getText().substring(0, tf.getText().length() - 1);elsetf.setText("0");IfResult = true;else if(str = "CE")tf.setText("0");IfResult = true;/* * 数字输入的事件监听 */class Num implements ActionListenerpublic void actionPerformed(ActionEvent e) String str = e.getActionCommand();if(IfResult)tf.setText("");IfResult = false;if(str="")tf.setText(String.valueOf(Math.PI);else if(str="e")tf.setText(String.valueOf(Math.E);elsetf.setText(tf.getText().trim() + str);if(tf.getText().equals("0")tf.setText("0");IfResult = true;flag = true;/* * 小数点的事件监听 */class Dot implements ActionListenerpublic void actionPerformed(ActionEvent e) IfResult = false;if(tf.getText().trim().indexOf(".") = -1)tf.setText(tf.getText() + ".");/* * main方法 */public static void main(String args) new Calucator().setVisible(true);Applet程序代码:import java.util.*;import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.applet.*;public class Calucator extends JApplet implements ActionListenerboolean i=true;private JButton num0=new JButton("0");private JButton num1=new JButton("1");private JButton num2=new JButton("2");private JButton num3=new JButton("3");private JButton num4=new JButton("4");private JButton num5=new JButton("5");private JButton num6=new JButton("6");private JButton num7=new JButton("7");private JButton num8=new JButton("8");private JButton num9=new JButton("9");private JButton zuok=new JButton("(");private JButton youk=new JButton(")");private JButton dian=new JButton(".");private JButton NULL=new JButton("N");private JButton plu=new JButton("+");private JButton min=new JButton("-");private JButton mul=new JButton("x");private JButton div=new JButton("/");private JButton equ=new JButton("=");private JButton cle=new JButton("C");/清除private JTextField space=new JTextField(30);public void init()JPanel text=new JPanel();text.setLayout(new FlowLayout();text.add(space);JPanel buttons=new JPanel();buttons.setLayout(new GridLayout(5,4);buttons.add(num9);buttons.add(num8);buttons.add(num7);buttons.add(plu);buttons.add(num6);buttons.add(num5);buttons.add(num4);buttons.add(min);buttons.add(num3);buttons.add(num2);buttons.add(num1);buttons.add(mul);buttons.add(num0);buttons.add(cle);buttons.add(equ);buttons.add(div);buttons.add(zuok);buttons.add(youk);buttons.add(dian);buttons.add(NULL);(num9).addActionListener(this);(num8).addActionListener(this);(num7).addActionListener(this);(num6).addActionListener(this);(num5).addActionListener(this);(num4).addActionListener(this);(num3).addActionListener(this);(num2).addActionListener(this);(num1).addActionListener(this);(num0).addActionListener(this);(plu).addActionListener(this);(min).addActionListener(this);(mul).addActionListener(this);(div).addActionListener(this);(equ).addActionListener(this);(cle).addActionListener(this);(zuok).addActionListener(this);(youk).addActionListener(this);(dian).addActionListener(this);setLayout(new BorderLayout();add("North",text);add("South",buttons);space.setText("0");public void actionPerformed(ActionEvent e)if(e.getSource()=num9)if(i=true)space.setText("9");i=false;else space.setText(space.getText()+'9');if(e.getSource()=num8)if(i=true)space.setText("8");i=false;else space.setText(space.getText()+'8');if(e.getSource()=num7)if(i=true)space.setText("7");i=false;else space.setText(space.getText()+'7');if(e.getSo

    注意事项

    本文(JAVA课程设计模拟科学计算器 .doc)为本站会员(laozhun)主动上传,三一办公仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知三一办公(点击联系客服),我们立即给予删除!

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




    备案号:宁ICP备20000045号-2

    经营许可证:宁B2-20210002

    宁公网安备 64010402000987号

    三一办公
    收起
    展开