简体   繁体   English

java Swing应用程序的例外?

[英]Exception for java Swing application?

For some reason this is locking up the java application. 出于某种原因,这是锁定java应用程序。 Did I handle the exception correctly? 我是否正确处理了异常?

private void submitButtonActionPerformed(java.awt.event.ActionEvent evt)    {                                             
    double amount, interest,rateCalc, a, b, c, payment;
    int years, months;
    while (true){
        try{
            amount = Double.valueOf(loanAmount.getText());
            interest = Double.valueOf(interestRate.getText());
            years = Integer.valueOf(loanYears.getText());
            rateCalc = (interest/12);
            months = (years*12);
            a = Math.pow((1+rateCalc),months);
            b = (a*rateCalc);
            c = (a-1);
            payment = (amount *(b/c));
            monthlyPayment.setText("Mortgage Payment $ = " + payment);

        } catch (NumberFormatException nfe){
            javax.swing.JOptionPane.showMessageDialog(null,
                    "Please enter numbers and not letters");
            return;
        }
    }

}

monthlyPayment returns to the java app. monthlyPayment返回java应用程序。

You are creating a loop in the Event Dispatch Thread. 您正在Event Dispatch Thread中创建一个循环。 This will cause your painting thread to spin, making it feel like your app is hanging and will not allow any other GUI actions to be performed. 这将导致您的绘制线程旋转,使您觉得您的应用程序挂起,并且不允许执行任何其他GUI操作。

I would remove the while(true) loop. 我会删除while(true)循环。

Try removing the while(true) statement. 尝试删除while(true)语句。 It shouldn't be necessary in your case. 在您的情况下,它不应该是必要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM