⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 computer.java

📁 Java 语言实现的计算器
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    p7.add(J);    p7.add(K);    p7.add(L);    p7.add(M);    p7.add(N);    //面板P8上添加按钮(O,P,Q,R,S,T,U)    p8.add(O);    p8.add(P);    p8.add(Q);    p8.add(R);    p8.add(S);    p8.add(T);    p8.add(U);    //面板P9上添加按钮(bp,W,X,Y,Z,i,bbb)    p9.add(bq);    p9.add(W);    p9.add(X);    p9.add(Y);    p9.add(Z);    p9.add(i);    p9.add(bbb);//添加窗口事件监听器,以监听关闭窗口事件    this.addWindowListener(new WindowAdapter() {      public void windowClosing(WindowEvent e) {        System.exit(0);      }    });    //给各个按菜单项和钮添加事件监听器    mm1.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        mem = tt.getText(); //使菜单项mm1具有复制功能      }    });    mm2.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        t.setText(mem); //使菜单项mm2具有粘贴功能      }    });    mm3.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        String s = tt.getText();        s += "欢迎您使用帮助主题:清空可以使用‘CE‘按钮或文件(F)中的清空按钮;复制可以使用按钮‘C(大写)‘或编辑中的复制(C);粘贴可以使用按钮‘P(大写)‘或使用编辑中的粘贴(P);退出可以使用按钮'EXIT'或文件中的退出(EXIT)。(如果您想了解更多的信息请看帮助中的关于计算器(a))!";        tt.setText(s);        //使菜单项mm3具有显示帮助主题功能      }    });    mm4.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        System.exit(0);//使菜单项mm4具有退出功能      }    });    mm5.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        String s = tt.getText();        s += "欢迎您使用帮助:J.S.L-计算器可以执行所有手持计算器完成的标准操作;它可以执行基本的运算,如加减乘除法,以及科学计算器中的函数,如三角函数,以e为底的指数和对数函数,还可以进行开方和绝对值运算。";        tt.setText(s);//使菜单项mm5具有显示关于计算器功能      }    });    mm8.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        String s = tt.getText();        s += "查看源文件请点击最上面的下拉框";        tt.setText(s);//使菜单项mm8具有查看源文件功能      }    });    mm9.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        t.setText("");        tt.setText("");//使菜单项mm9具有清空功能      }    });//可以在文本框中显示数字0    b0.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        String s = t.getText();        s += "0";        t.setText(s);      }    });//可以在文本框中显示数字1    b1.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        String s = t.getText();        s += "1";        t.setText(s);      }    }); //可以在文本框中显示数字2    b2.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        String s = t.getText();        s += "2";        t.setText(s);      }    }); //可以在文本框中显示数字3    b3.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        String s = t.getText();        s += "3";        t.setText(s);      }    }); //可以在文本框中显示数字4    b4.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        String s = t.getText();        s += "4";        t.setText(s);      }    }); //可以在文本框中显示数字5    b5.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        String s = t.getText();        s += "5";        t.setText(s);      }    }); //可以在文本框中显示数字6    b6.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        String s = t.getText();        s += "6";        t.setText(s);      }    }); //可以在文本框中显示数字7    b7.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        String s = t.getText();        s += "7";        t.setText(s);      }    }); //可以在文本框中显示数字8    b8.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        String s = t.getText();        s += "8";        t.setText(s);      }    }); //可以在文本框中显示数字9    b9.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        String s = t.getText();        s += "9";        t.setText(s);      }    }); //可以在文本框中显示负号    bo.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        String s = t.getText();        s += "-";        t.setText(s);      }    });    bp.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        t.setText(mem); //使按钮bp具有粘贴功能      }    });    bq.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        mem = tt.getText(); //使按钮bq具有复制功能      }    }); //可以在文本框中显示数字2.7183    br.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        String s = t.getText();        s += "2.7183";        t.setText(s);      }    });//可以进行sin运算    bg.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        String s = t.getText();        double b = Double.parseDouble(s);        b *= Math.PI / 180;        b = Math.sin(b);        b = b * 10000;        b = Math.rint(b);        b = b / 10000;        tt.setText("" + b);      }    }); //可以进行cos运算    bh.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        String s = t.getText();        double b = Double.parseDouble(s);        b *= Math.PI / 180;        b = Math.cos(b);        b = b * 10000;        b = Math.rint(b);        b = b / 10000;        tt.setText("" + b);      }    }); //可以进行tan运算    bi.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        String s = t.getText();        double b = Double.parseDouble(s);        b *= Math.PI / 180;        b = Math.tan(b);        b = b * 10000;        b = Math.rint(b);        b = b / 10000;        tt.setText("" + b);      }    }); //可以进行exp运算    bl.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        String s = t.getText();        double b = Double.parseDouble(s);        b = Math.exp(b);        b = b * 10000;        b = Math.rint(b);        b = b / 10000;        tt.setText("" + b);      }    }); //可以进行sqrt运算    bj.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        String s = t.getText();        double b = Double.parseDouble(s);        b = Math.sqrt(b);        b = b * 10000;        b = Math.rint(b);        b = b / 10000;        tt.setText("" + b);      }    }); //可以进行log运算    bm.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        String s = t.getText();        double b = Double.parseDouble(s);        b = Math.log(b);        b = b * 10000;        b = Math.rint(b);        b = b / 10000;        tt.setText("" + b);      }    }); //可以进行abs运算    bn.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        String s = t.getText();        double b = Double.parseDouble(s);        b = Math.abs(b);        b = b * 10000;        b = Math.rint(b);        b = b / 10000;        tt.setText("" + b);      }    });    bk.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        t.setText("");        tt.setText(""); //使按钮bk具有清空功能      }    });    //添加加号事件监听器    ba.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        s1 = t.getText(); //得到加号前文本框t中的内容        op = '+'; //将运算符设置为加        t.setText(""); //清空输入文本框t中的内容      }    }); //添加减号事件监听器    bb.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        s1 = t.getText(); //得到加号前文本框t中的内容        op = '-'; ; //将运算符设置为减        t.setText(""); //清空输入文本框t中的内容      }    }); //添加乘号事件监听器    bc.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        s1 = t.getText(); //得到加号前文本框t中的内容        op = '*'; ; //将运算符设置为乘        t.setText(""); //清空输入文本框t中的内容      }    }); //添加除号事件监听器    bd.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        s1 = t.getText(); //得到加号前文本框t中的内容        op = '/'; ; //将运算符设置为除        t.setText(""); //清空输入文本框t中的内容      }    });    be.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        String s = t.getText();        s += ".";        t.setText(s);//可以在文本框中显示数字小数点      }    }); //添加等号事件监听器    bf.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        s2 = t.getText(); //得到加号后文本框t中的内容        u1 = Double.parseDouble(s1); //表示s1被强类型转化为浮点数        u2 = Double.parseDouble(s2); //表示s2被强类型转化为浮点数        if (op == '+') { //如果运算符为加号          u3 = u1 + u2;        }        if (op == '-') { //如果运算符为减号          u3 = u1 - u2;        }        if (op == '*') { //如果运算符为乘号          u3 = u1 * u2;        }        if (op == '/') { //如果运算符为除号          u3 = u1 / u2;        }        tt.setText("" + u3); //在文本域中显示计算结果      }    });    bbb.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        System.exit(0);//使按钮bbb具有退出功能

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -