77范文网 - 专业文章范例文档资料分享平台

大数加减运算(3)

来源:网络收集 时间:2019-03-16 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

图:加法示例2

3.减法

图:减法示例

9

第四章 实验总结

刚拿到课设的题目时,我对大数运算了解有限。为了保证代码的高效性,特地参考了《算法导论》。

回顾这次课设的过程,我感概颇多,在这段时间,需要经常从电脑上查询资料,查看书本了解一些函数的使用方法,当然,写代码的过程也充满了各种挫折,每每满心欢喜的运行已经写好的代码时,总会出现各种意料之外的bug,然后又去苦思解决方案,这样反反复复的修改,最终才形成了现在的代码,虽然这个代码还不是最完美的,但是却锻炼了我独立思考的能力,更重要的是我也学到了很多之前没有学过的东西,让我受益匪浅。这次做课设也让我明白了查阅资料的重要性,在信息化多元的今天,我们不可能掌握所有的知识,面对未知的事物,学会查阅书籍和上网搜集是必不可少的。

对于这些代码还是有很大的改进空间的:1.界面上的输入框并不友好,当用户输入3个数后不能自动追加空格,数字都没有空格隔开。2.对于结果不支持让用户选择精度的科学计数法。

10

第五章附录:程序源代码

1.输入与显示模块:UI类

package ncu;

import java.awt.BorderLayout; import java.awt.Font;

import java.awt.GridLayout;

import java.awt.event.ActionEvent; import java.awt.event.ActionListener; importjava.util.regex.Matcher; importjava.util.regex.Pattern; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.SwingUtilities; import javax.swing.UIManager;

publicclassUIextends JFrame { private JTextArea firstNum; private JTextArea nextNum; private JTextArea result; private String resultStr; private JButton add; private JButton sub; private String num1; private String num2; public UI() { this.setWinStyle(); this.initGUI(); this.setMyFont(); this.Listener(); this.setSize(700, 400); this.setLocationRelativeTo(null); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

this.setTitle(\大数运算\); this.setVisible(true);

11

//设置字体

privatevoid setMyFont(){ Font font= new Font(\,Font.BOLD,22); this.firstNum.setFont(font); this.nextNum.setFont(font); this.result.setFont(font); }

//初始化页面

privatevoid initGUI() {

JPanel pn = new JPanel();

pn.setLayout(new GridLayout(2, 1, 0, 4)); JPanel first = new JPanel();

first.setLayout(new BorderLayout(4, 4));

first.add(new JLabel(\第一个数:\), BorderLayout.WEST); this.firstNum = new JTextArea(15, 4); firstNum.setLineWrap(true);

JScrollPane scrollNum1 = new JScrollPane(); scrollNum1.setViewportView(firstNum);

first.add(scrollNum1, BorderLayout.CENTER); JButton btn1 = new JButton(\清除\); first.add(btn1, BorderLayout.EAST); // this.add(first); pn.add(first);

JPanel next = new JPanel();

next.setLayout(new BorderLayout(4, 4));

next.add(new JLabel(\第二个数:\), BorderLayout.WEST); this.nextNum = new JTextArea(15, 4); nextNum.setLineWrap(true);

JScrollPane scrollNum2 = new JScrollPane(); scrollNum2.setViewportView(nextNum);

next.add(scrollNum2, BorderLayout.CENTER); JButton btn2 = new JButton(\清除\); next.add(btn2, BorderLayout.EAST); // this.add(next); pn.add(next);

JPanel panel = new JPanel();

panel.setLayout(new BorderLayout());

this.add = new JButton(\加法\);

12

this.sub = new JButton(\减法\); JPanel type = new JPanel();

type.setLayout(new BorderLayout(4, 4));

type.add(new JLabel(\运算类型:\), BorderLayout.WEST); JPanel kind = new JPanel();

type.add(kind, BorderLayout.CENTER); kind.setLayout(new GridLayout(1, 2)); kind.add(this.add); kind.add(this.sub);

panel.add(type, BorderLayout.NORTH); // this.add(type);

this.result = new JTextArea();

JScrollPane scroll = new JScrollPane(); this.result.setEditable(false); this.result.setLineWrap(true);

this.result.setWrapStyleWord(true); scroll.setViewportView(result);

scroll.setColumnHeaderView(new JLabel(\运算结果:\)); panel.add(scroll, BorderLayout.CENTER); // this.add(scroll);

this.setLayout(new GridLayout(2, 1, 0, 4)); this.add(pn); this.add(panel);

//清除输入1

btn1.addActionListener(new ActionListener() {

@Override publicvoid actionPerformed(ActionEvent e) { firstNum.setText(null); } }); //清除输入2 btn2.addActionListener(new ActionListener() { @Override publicvoid actionPerformed(ActionEvent e) { nextNum.setText(null); } }); } //初始化监听器 privatevoid Listener() { this.add.addActionListener(new ActionListener() {

13

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库大数加减运算(3)在线全文阅读。

大数加减运算(3).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/zonghe/526992.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: