actionhandler.java

来自「用java开发的一个个人所得税计算程序」· Java 代码 · 共 58 行

JAVA
58
字号
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package 实验一;import javax.swing.*;import java.awt.event.*;import java.awt.*;public class ActionHandler implements ActionListener{    ActionHandler(TexFrame p) {        op=p;    }    public void actionPerformed(ActionEvent e) {        String cmd=e.getActionCommand();                 //获取事件源        if (cmd.equals("计算")) {            //按下“计算”按钮,执行计算            if (op.input.getText().equals("")) {         //未输入金额时,不进行任何操作                JOptionPane.showMessageDialog( null , "请输入金额" ,"提示" , JOptionPane.ERROR_MESSAGE) ;            }            else {                boolean isDigit;  //输入字符是否为数字字符串                try{                    float dTemp=Float.parseFloat(op.input.getText());                    isDigit=true;                }catch(Exception ex) {                    isDigit=false;                }                if(isDigit){    //输入字符串为数字字符串                    boolean isDigit1;  //输入字符是否为数字字符串                    try{                        float   dTemp1   =Float.parseFloat(op.start.getText());                        isDigit1=true;                    }catch(Exception   ex) {                        isDigit1=false;                        JOptionPane.showMessageDialog( null , "输入起征点有错有错" ,"提示" , JOptionPane.ERROR_MESSAGE) ;                    }                    if(isDigit1){                        op.chJumpoffPoint(Integer.parseInt(op.start.getText()));                        float m=Float.parseFloat(op.input.getText());  //读取输入数据                        op.setMoney(m);                        op.counter();                                //计算个人所得税                        op.output.setText(op.getResult()+"");        //显示计算结果                    }                }                else {                    JOptionPane.showMessageDialog( null , "输入金额有错" ,"提示" , JOptionPane.ERROR_MESSAGE) ;                }            }        }    }    private TexFrame op;}

⌨️ 快捷键说明

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