import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
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 java.io.*;
import java.util.Date;
public class WinFrame extends JFrame {
public JPanel buttomjpanel;
public JPanel leftpanel;
public JPanel rightpanel;
public JTextArea jtextareaa;
public JTextArea jtextareab;
public JTextArea jtextarearesult;
public JLabel timeshow;
int aLength = 1000,bLength = 900;
BigNumber a = null;
BigNumber b = null;
public String result="";
public String time="";
public static long start,end;//时间
public static void setStartTime(long s){
start = s;
}
public static void setEndTime(long e){
end = e;
}
public WinFrame(){
super("大数运算器");
this.setBounds(200,200,680, 400);
this.setLayout(null);
this.init();
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void init(){
this.buttomjpanel=new JPanel();
this.buttomjpanel.setBounds(0, 0, 680,400);
this.buttomjpanel.setBackground(Color.white);
this.buttomjpanel.setLayout(null);
this.leftpanel=new JPanel();
this.leftpanel.setLayout(null);
this.leftpanel.setBounds(0,0,550,400);
this.leftpanel.setBackground(Color.white);
JLabel abiao=new JLabel();
abiao.setText("大数a:");
abiao.setBounds(5,0,50,100);
this.leftpanel.add(abiao);
this.jtextareaa=new JTextArea(5,45);
JScrollPane jspa=new JScrollPane(jtextareaa);
this.jtextareaa.setEditable(false);
this.jtextareaa.setLineWrap(true);
jspa.setBounds(50,0,500,100);
this.jtextareaa.setBackground(Color.white);
jspa.setBackground(Color.white);
this.leftpanel.add(jspa);
JLabel bbiao=new JLabel();
bbiao.setText("大数b:");
bbiao.setBounds(5,100,50,100);
this.leftpanel.add(bbiao);
this.jtextareab=new JTextArea(5,45);
JScrollPane jspb=new JScrollPane(jtextareab);
jtextareab.setEditable(false);
this.jtextareab.setLineWrap(true);
jspb.setBounds(50,100,500,100);
this.jtextareab.setBackground(Color.white);
jspb.setBackground(Color.white);
this.leftpanel.add(jspb);
JLabel timebiao=new JLabel();
timebiao.setText("用时(秒):");
timebiao.setBounds(5,200,100,50);
this.leftpanel.add(timebiao);
this.timeshow=new JLabel();
timeshow.setBounds(100,200,100,50);
this.leftpanel.add(this.timeshow);
JLabel resultbiao=new JLabel();
resultbiao.setText("结果:");
resultbiao.setBounds(5,250,50,50);
this.leftpanel.add(resultbiao);
this.jtextarearesult=new JTextArea(5,45);
JScrollPane jspr=new JScrollPane(jtextarearesult);
jtextarearesult.setEditable(false);
this.jtextarearesult.setLineWrap(true);
jspr.setBounds(50,250,500,100);
this.jtextarearesult.setBackground(Color.white);
jspr.setBackground(Color.white);
this.leftpanel.add(jspr);
this.buttomjpanel.add(this.leftpanel);
this.rightpanel=new JPanel();
this.rightpanel.setLayout(null);
this.rightpanel.setBounds(550,0,100,500);
this.rightpanel.setBackground(Color.white);
JButton qingling=new JButton("清零");
qingling.setBounds(0,5,100,40);
qingling.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
jtextareaa.setText("");
jtextareab.setText("");
jtextarearesult.setText("");
timeshow.setText("");
}
});
this.rightpanel.add(qingling);
JButton bianhuan=new JButton("变数");
bianhuan.setBounds(0,55,100,40);
bianhuan.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
setStartTime(System.currentTimeMillis());
jtextareaa.setText((a=new BigNumber(1000)).toString());
jtextareab.setText((b=new BigNumber(900)).toString());
jtextarearesult.setText("");
setEndTime(System.currentTimeMillis());
timeshow.setText((end-start)+"");
writeToFile("a:"+a.toString());
writeToFile("b:"+b.toString());
}
});
this.rightpanel.add(bianhuan);
JButton jia=new JButton("加");
jia.setBounds(0,105,100,40);
jia.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
if(null!=a&&null!=b){
setStartTime(System.currentTimeMillis());
try{
jtextarearesult.setText(a.plus(b).toString());
}catch(Exception e){
writeToFile(e.toString());
}
setEndTime(System.currentTimeMillis());
timeshow.setText((end-start)+"");
writeToFile("a+b:"+jtextarearesult.getText());
}
}
});
this.rightpanel.add(jia);
JButton jian=new JButton("减");
jian.setBounds(0,155,100,40);
jian.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
if(null!=a&&null!=b){
setStartTime(System.currentTimeMillis());
try {
jtextarearesult.setText(a.sub(b).toString());
} catch (Exception e) {
writeToFile(e.toString());
}
setEndTime(System.currentTimeMillis());
timeshow.setText((end-start)+"");
writeToFile("a-b:"+jtextarearesult.getText());
}
}
});
this.rightpanel.add(jian);
JButton cheng=new JButton("乘");
cheng.setBounds(0,205,100,40);
cheng.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
if(null!=a&&null!=b){
setStartTime(System.currentTimeMillis());
try {
jtextarearesult.setText(a.multiply(b).toString());
} catch (Exception e) {
writeToFile(e.toString());
}
setEndTime(System.currentTimeMillis());
timeshow.setText((end-start)+"");
writeToFile("a*b:"+jtextarearesult.getText());
}
}
});
this.rightpanel.add(cheng);
JButton chu=new JButton("除");
chu.setBounds(0,255,100,40);
chu.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
if(null!=a&&null!=b){
setStartTime(System.currentTimeMillis());
//jtextarearesult.setText("尚未实现");
try {
jtextarearesult.setText(a.divide(b).toString());
} catch (Exception e) {
writeToFile(e.toString());
}
setEndTime(System.currentTimeMillis());
timeshow.setText((end-start)+"");
}
}
});
this.rightpanel.add(chu);
this.buttomjpanel.add(this.rightpanel);
this.add(this.buttomjpanel);
}
public void writeToFile(String s){
File f = new File("./log.txt");
Date d = new Date();
try{
BufferedWriter bf = new BufferedWriter(new FileWriter(f,true));
bf.write(d.toLocaleString());
bf.write(s);
bf.close();
}catch(IOException e){ e.printStackTrace();}
}
public static void main(String args[]){
new WinFrame();
}
}
java 数组实现大数加减乘除运算
5星 · 超过95%的资源 需积分: 47 139 浏览量
2009-10-17
00:20:17
上传
评论 12
收藏 3KB RAR 举报
l546753716
- 粉丝: 0
- 资源: 9
最新资源
- Screenshot_20240427_031602.jpg
- 网页PDF_2024年04月26日 23-46-14_QQ浏览器网页保存_QQ浏览器转格式(6).docx
- 直接插入排序,冒泡排序,直接选择排序.zip
- 在排序2的基础上,再次对快排进行优化,其次增加快排非递归,归并排序,归并排序非递归版.zip
- 实现了7种排序算法.三种复杂度排序.三种nlogn复杂度排序(堆排序,归并排序,快速排序)一种线性复杂度的排序.zip
- 冒泡排序 直接选择排序 直接插入排序 随机快速排序 归并排序 堆排序.zip
- 课设-内部排序算法比较 包括冒泡排序、直接插入排序、简单选择排序、快速排序、希尔排序、归并排序和堆排序.zip
- Python排序算法.zip
- C语言实现直接插入排序、希尔排序、选择排序、冒泡排序、堆排序、快速排序、归并排序、计数排序,并带图详解.zip
- 常用工具集参考用于图像等数据处理
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
- 4
- 5
- 6
前往页