JRadioButton Java GUI

时间:2018-04-23 09:04:45

标签: java jbutton

JButton calculateBtn = new JButton("Calculate");
calculateBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {

    int iStart, fRate, gen;

    try {
        iStart = Integer.parseInt(startText.getText());
        fRate = Integer.parseInt(fixedText.getText());
        gen = Integer.parseInt(genText.getText());

        if(FixedRad.isSelected()) {                                             
            for(int a = 0; a < gen; a++) {
                iStart += iStart*fRate/100; 
            }
        } else {
            int vara, varb, varc, vard, vare, varf, varg, varh, vari, varj;
            vara = Integer.parseInt(var1.getText());
            varb = Integer.parseInt(var2.getText());
            varc = Integer.parseInt(var3.getText());
            vard = Integer.parseInt(var4.getText());
            vare = Integer.parseInt(var5.getText());
            varf = Integer.parseInt(var6.getText());
            varg = Integer.parseInt(var7.getText());
            varh = Integer.parseInt(var8.getText());
            vari = Integer.parseInt(var9.getText());
            varj = Integer.parseInt(var10.getText());

            int[] iaGrowthRate = {vara, varb, varc, vard, vare, varf, varg, varh, vari, varj};
            for( int a = 0; a < 10; a++) {
                iStart += iStart*iaGrowthRate[a]/100;
                }
            }

            } catch (Exception e1) {

                JOptionPane.showMessageDialog(null,  "Plese enter a Valid Number");
            }
        }
    });

第一个按钮完美运行(FixedRad),但是当我尝试选择变量按钮时它不起作用并且消息&#34;请输入有效数字&#34;

谢谢!

0 个答案:

没有答案