java 编写计算器的简单程序//一个较为简洁的巧妙的计算器程序, import java.io.*; import java.awt.event.*; import java.awt.*; //需要解决的问题,数学的运算都有正负号的出现,在点击等号的时候就会有冲突,应该怎样解决,经验:双精度浮点型数据类型是会像后减一位。0.7会显示成0.69999999 public class app74 { static int i=0; static int j=0; static int k=-1; static int l=-1; //static int Data1[]={1}; static String str9=""; static Frame frm1=new Frame("计算器"); static Button btn1=new Button("1"); static Button btn2=new Button("2"); static Button btn3=new Button("3"); static Button btn5=new Button("4"); static Button btn6=new Button("5"); static Button btn7=new Button("6"); static Button btn9=new Button("7"); static Button btn14=new Button("8"); static Button btn16=new Button("9"); static Button btn11=new Button("0");//数字0 static Button btn4=new Button("."); static Button btn8=new Button("+"); static Button btn10=new Button("-"); static Button btn15=new Button("*"); static Button btn13=new Button("/"); static Button btn20=new Button("="); static Button btn18=new Button("清零"); static Button btn19=new Button("后退"); static Button btn12=new Button("π"); static Button btn17=new Button("颜色"); static TextField TF1=new TextField(); static Label Lb1=new Label(".0",Label.RIGHT); //标签 static Label Lb2=new Label(".0",Label.RIGHT); //BS字符长度 static Label Lb3=new Label(".0",Label.RIGHT); //对象str22字符长度 static Label Lb4=new Label(".0",Label.RIGHT); //BS剩余字符长度字符长度 static Label Lb5=new Label("无",Label.LEFT); //执行错误抛出 static Label Lb6=new Label("对象BS字符长度 : ",Label.LEFT); static Label Lb7=new Label("对象str22字符长度 :",Label.LEFT); static Label Lb8=new Label("对象BS剩余字符长度:",Label.LEFT); static Label Lb9=new Label("错误:",Label.LEFT); static Label Lb10=new Label(".0",Label.RIGHT); //计算器下面的标签 static Label Lb11=new Label("余数:",Label.RIGHT); //余数标签 static Label Lb12=new Label(".0",Label.RIGHT); static TextArea TA=new TextArea("说明:由于软件不够完善,请规范运算的输入:1.可在里面按键输入",1000,TextArea.SCROLLBARS_VERTICAL_ONLY); static TextField TF=new TextField(); static GridLayout GL1=new GridLayout(5,4); //流动布局 static Panel Pl=new Panel(); //面板 static BorderLayout BL=new BorderLayout(); static shijian app1=new shijian(); //实现监听器的类对象 static char Data2[]=new char[5]; static Font fnt=new Font("Serief",Font.ITALIC+Font.BOLD,18); static Font fnt2=new Font("Serief",Font.BOLD,15); static String str22; static StringBuffer BS=new StringBuffer(""); //可创建空的字符串对象,这个很重要 static String str23=str22; public static void main(String args[]) throws IOException { frm1.setLayout(null); Pl.setLayout(GL1);//面板加入布局 frm1.setSize(253,450);//没有设置窗口大小 frm1.setLocation(250,450); Lb1.setBounds(0,55,250,25);//计算器数字输入显示框之一上边框 Pl.setBounds(0,80,250,290); Lb2.setBounds(370,60,50,25); Lb3.setBounds(370,90,50,25); Lb4.setBounds(370,120,50,25); Lb5.setBounds(300,150,320,25); Lb6.setBounds(250,60,120,25); Lb7.setBounds(250,90,120,25); Lb8.setBounds(250,120,120,25); Lb9.setBounds(250,150,30,25); Lb10.setBounds(0,365,250,30);//计算器数字输入显示框之一下边框 Lb11.setBounds(250,30,120,25); Lb12.setBounds(370,30,50,25); TF.setBounds(0,30,250,25); TA.setBounds(0,395,250,75); TA.setEditable(false); Pl.add(btn1);//面板 Pl.add(btn2); Pl.add(btn3); Pl.add(btn4); Pl.add(btn5); Pl.add(btn6); Pl.add(btn7); Pl.add(btn8); Pl.add(btn9);//加入按钮 Pl.add(btn14); Pl.add(btn16); Pl.add(btn17); Pl.add(btn10);//加 Pl.add(btn11);//减 Pl.add(btn12);//乘 Pl.add(btn13);//除 Pl.add(btn15);//这里是等号注意事件的监听器在不同的类上 Pl.add(btn17); Pl.add(btn18); Pl.add(btn19); Pl.add(btn20); frm1.add(Pl);//加入面板 frm1.addWindowListener(new shijian2()); frm1.add(Lb1); frm1.add(Lb2); frm1.add(Lb3); frm1.add(Lb4); frm1.add(Lb5); frm1.add(Lb6); frm1.add(Lb7); frm1.add(Lb8); frm1.add(Lb9); frm1.add(Lb10); frm1.add(Lb11); frm1.add(Lb12); frm1.add(TA); frm1.add(TF); //Lb2.setBackground(Color.pink); //Lb3.setBackground(Color.pink); //Lb4.setBackground(Color.pink); //Lb5.setBackground(Color.white); Lb6.setBackground(Color.white); Lb7.setBackground(Color.white); Lb8.setBackground(Color.white); Lb9.setBackground(Color.white); Lb10.setBackground(Color.gray); Lb11.setBackground(Color.white); TF.setBackground(Color.pink); //TA.setBackground(Color.pink); //Lb12.setBackground(Color.gray); Lb1.setFont(fnt); Lb2.setFont(fnt); Lb3.setFont(fnt); Lb4.setFont(fnt); Lb10.setFont(fnt); Lb11.setFont(fnt2); Lb12.setFont(fnt); Lb1.setBackground(Color.gray); btn1.addActionListener(app1); btn2.addActionListener(app1); btn3.addActionListener(app1); btn4.addActionListener(app1); btn5.addActionListener(app1); btn6.addActionListener(app1); btn7.addActionListener(app1); btn8.addActionListener(app1); btn9.addActionListener(app1); btn10.addActionListener(app1); btn11.addActionListener(app1); btn12.addActionListener(app1); //btn12.addActionListener(app1);//写两个这个则会被触发两次事件 btn13.addActionListener(app1); btn14.addActionListener(app1); btn15.addActionListener(app1); btn16.addActionListener(app1); btn17.addActionListener(app1); btn18.addActionListener(app1); btn19.addActionListener(app1); btn20.addActionListener(app1); TF.addTextListener(new shijian3()); frm1.setBackground(Color.white); frm1.setResizable(false); frm1.setVisible(true);//可见 } static class shijian implements ActionListener//接口的实现 { public void actionPerformed(ActionEvent e) { Button BT=(Button)e.getSource(); //取得事件的对象,用于判断事件所属 String str1=BT.getLabel(); //取得按钮的名字,也就是相应的数字 if(str1=="0"||str1=="1"||str1=="2"||str1=="3"||str1=="4"||str1=="5"||str1=="6"||str1=="7"||str1=="8"||str1=="9"||str1=="+"||str1=="-"||str1=="*"||str1=="/"||str1=="."||str1=="π") { if(str1=="π"){str1=Double.toString(Math.PI);} BS.append(str1);//将得到的字符串加入到原有字符串 String str22=BS.toString();//转换成字符串 String str56=Integer.toString(str22.length());//将整形转换成字符串 Lb10.setText(str22); Lb2.setText(str56); Lb3.setText(str56); Lb4.setText(str56); Lb5.setText("无"); Lb12.setText(".0"); Lb1.setText(str22); try{ FileWriter FQ=new FileWriter("D:\\java\\10.txt");FQ.write(str22);FQ.flush();} catch(Exception u) {System.out.println("出错了");}} if(str1=="=")//如果等于等号if里面包含多个if或者while { // System.out.println("str22="+str22); char Data[]=new char[BS.length()]; try{ FileReader FV=new FileReader("D:\\java\\10.txt");//写入所需数据 FV.read(Data);} //这是我们写入的数据, catch(Exception y){System.out.println("出错了");} while(k
2023-12-19 07:02:42 110KB java
1
简单实现计算器的加减乘除。设计简单,代码容易看懂,适合初学者学习。
2023-12-17 08:02:27 3.49MB
1
实现了一个基于Python matplotlib的函数绘图计算器,可实现二维三维绘图和解线性方程组,全部图形界面显示,界面友好,易操作,有详细的readMe指导和注释。
2023-12-16 17:02:06 43KB Python matplotlib
1
MFC计算器源码+动态库源码,打开计算器之后,用VC打开计算器.dsw,编译,运行之后,会出一个缺少动态库的提示,把该文件夹下的jsp.dll拷贝到Debug下再次运行程序
2023-12-15 23:12:44 4.47MB
1
MFC制作的简单的计算器程序,VC6.0编译通过。
2023-12-15 23:06:22 33KB 计算器
1
MFC计算器课程设计报告,C++,内附完全代码
2023-12-15 23:05:05 76KB MFC计算器课程设计报告
1
.CPP文件 与可执行文件 课程设计任务:开发一个基于对话框的简易计算器。要求具有简单的加减乘除计算功能。
2023-12-15 22:58:54 87KB MFC-计算器
1
MFC 加法计算器 + 模态对话框 完整工程代码下载 MFC 加法计算器 + 模态对话框 完整工程代码下载 MFC 加法计算器 + 模态对话框 完整工程代码下载 MFC 加法计算器 + 模态对话框 完整工程代码下载 MFC 加法计算器 + 模态对话框 完整工程代码下载 MFC 加法计算器 + 模态对话框 完整工程代码下载 MFC 加法计算器 + 模态对话框 完整工程代码下载 MFC 加法计算器 + 模态对话框 完整工程代码下载 MFC 加法计算器 + 模态对话框 完整工程代码下载 MFC 加法计算器 + 模态对话框 完整工程代码下载 MFC 加法计算器 + 模态对话框 完整工程代码下载 MFC 加法计算器 + 模态对话框 完整工程代码下载 MFC 加法计算器 + 模态对话框 完整工程代码下载 MFC 加法计算器 + 模态对话框 完整工程代码下载 MFC 加法计算器 + 模态对话框 完整工程代码下载 MFC 加法计算器 + 模态对话框
2023-12-15 22:56:49 152.47MB
1
gpa计算器源代码,课程设计,c++元源代码
2023-12-12 08:01:37 54KB
1
这只是一个简单计算器,模仿Windows XP下的自带计算器,完成标准型计算器的编写
2023-12-11 10:14:50 430KB Delphi 计算器
1