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

📄 jsq.java~2~

📁 用java语言实现的简单计算器
💻 JAVA~2~
📖 第 1 页 / 共 2 页
字号:
        }

        //5的事件监听器
        public void btn5_actionPerformed(ActionEvent e){
                if (flag) {
            txtResult.setText(btn5.getActionCommand());
            flag = false;
        }
        else {
            txtResult.setText(txtResult.getText() + btn5.getActionCommand());
        }
        }

        class btn5 implements ActionListener{

                private jsq adaptee;

                btn5(jsq adaptee){

                        this.adaptee=adaptee;
                }

                public void actionPerformed(ActionEvent e){

                        adaptee.btn5_actionPerformed(e);
                }
        }


        //6的事件监听器
        public void btn6_actionPerformed(ActionEvent e){
                if (flag) {
            txtResult.setText(btn6.getActionCommand());
            flag = false;
        }
        else {
            txtResult.setText(txtResult.getText() + btn6.getActionCommand());
        }
        }

        class btn6 implements ActionListener{

                private jsq adaptee;

                btn6(jsq adaptee){

                        this.adaptee=adaptee;
                }

                public void actionPerformed(ActionEvent e){

                        adaptee.btn6_actionPerformed(e);
                }
        }


        //7的事件监听器
        public void btn7_actionPerformed(ActionEvent e){
                if (flag) {
            txtResult.setText(btn7.getActionCommand());
            flag = false;
        }
        else {
            txtResult.setText(txtResult.getText() + btn7.getActionCommand());
        }
        }

        class btn7 implements ActionListener{

                private jsq adaptee;

                btn7(jsq adaptee){

                        this.adaptee=adaptee;
                }

                public void actionPerformed(ActionEvent e){

                        adaptee.btn7_actionPerformed(e);
                }
        }


        //8的事件监听器
        public void btn8_actionPerformed(ActionEvent e){
                if (flag) {
            txtResult.setText(btn8.getActionCommand());
            flag = false;
        }
        else {
            txtResult.setText(txtResult.getText() + btn8.getActionCommand());
        }
        }

        class btn8 implements ActionListener{

                private jsq adaptee;

                btn8(jsq adaptee){

                        this.adaptee=adaptee;
                }

                public void actionPerformed(ActionEvent e){

                        adaptee.btn8_actionPerformed(e);
                }
        }


        //9的事件监听器
        public void btn9_actionPerformed(ActionEvent e){
                if (flag) {
            txtResult.setText(btn9.getActionCommand());
            flag = false;
        }
        else {
            txtResult.setText(txtResult.getText() + btn9.getActionCommand());
        }
        }

        class btn9 implements ActionListener{

                private jsq adaptee;

                btn9(jsq adaptee){

                        this.adaptee=adaptee;
                }

                public void actionPerformed(ActionEvent e){

                        adaptee.btn9_actionPerformed(e);
                }
        }

        //清除按钮事件监听器
        public void btnClear_actionPerformed(ActionEvent e){

                txtResult.setText("");
        }

        class btnClear implements ActionListener{

                private jsq adaptee;

                btnClear(jsq adaptee){

                        this.adaptee=adaptee;
                }

                public void actionPerformed(ActionEvent e){

                        adaptee.btnClear_actionPerformed(e);
                }
        }

        //+操作符事件监听器
        public void btnPlus_actionPerformed(ActionEvent e){

                operand1 = txtResult.getText();
                action = "plus";
                flag = true;
        }

        class btnPlus implements ActionListener{

                private jsq adaptee;

                btnPlus(jsq adaptee){

                        this.adaptee=adaptee;
                }

                public void actionPerformed(ActionEvent e){

                        adaptee.btnPlus_actionPerformed(e);
                }
        }

        //-操作符事件监听器
        public void btnMinus_actionPerformed(ActionEvent e){

                operand1 = txtResult.getText();
                action = "minus";
                flag = true;
        }

        class btnMinus implements ActionListener{

                private jsq adaptee;

                btnMinus(jsq adaptee){

                        this.adaptee=adaptee;
                }

                public void actionPerformed(ActionEvent e){

                        adaptee.btnMinus_actionPerformed(e);
                }
        }

        //*操作符事件监听器
        public void btnMultiply_actionPerformed(ActionEvent e){

                operand1 = txtResult.getText();
                action = "multiply";
                flag = true;
        }

        class btnMultiply implements ActionListener{

                private jsq adaptee;

                btnMultiply(jsq adaptee){

                        this.adaptee=adaptee;
                }

                public void actionPerformed(ActionEvent e){

                        adaptee.btnMultiply_actionPerformed(e);
                }
        }

        //除操作符事件监听器
        public void btnDivide_actionPerformed(ActionEvent e){

                operand1 = txtResult.getText();
                action = "divide";
                flag = true;
        }

        class btnDivide implements ActionListener{

                private jsq adaptee;

                btnDivide(jsq adaptee){

                        this.adaptee=adaptee;
                }

                public void actionPerformed(ActionEvent e){

                        adaptee.btnDivide_actionPerformed(e);
                }
        }

        //=操作符事件监听器
        public void btnEqual_actionPerformed(ActionEvent e){

                double digit1;

                double digit2;

                operand2=txtResult.getText();

                if(!flag){

                        if(action.equals("plus")){
                                digit1 = Double.parseDouble(operand1);
                                digit2 = Double.parseDouble(operand2);
                                result = digit1 + digit2;
                                txtResult.setText(""+result);
                                flag = true;
                        }
                        else if(action.equals("minus")){

                                digit1 = Double.parseDouble(operand1);
                                digit2 = Double.parseDouble(operand2);
                                result = digit1-digit2;
                                txtResult.setText(""+result);
                                flag = true;
                        }
                        else if(action.equals("multiply")){

                                digit1 = Double.parseDouble(operand1);
                                digit2 = Double.parseDouble(operand2);
                                result = digit1*digit2;
                                txtResult.setText(""+result);
                                flag = true;
                        }
                        else if(action.equals("divide")){

                                digit1 = Double.parseDouble(operand1);
                                digit2 = Double.parseDouble(operand2);
                                result = digit1/digit2;
                                txtResult.setText(""+result);
                                flag = true;
                        }
                }
        }

        class btnEqual implements ActionListener{

                private jsq adaptee;

                btnEqual(jsq adaptee){

                        this.adaptee=adaptee;
                }

                public void actionPerformed(ActionEvent e){

                        adaptee.btnEqual_actionPerformed(e);
                }
        }
}

⌨️ 快捷键说明

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