Exception for java Swing application?

Posted by Rich Fluckiger on Stack Overflow See other posts from Stack Overflow or by Rich Fluckiger
Published on 2010-05-29T21:45:02Z Indexed on 2010/05/29 21:52 UTC
Read the original article Hit count: 142

Filed under:

For some reason this is locking up the java application. 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.

© Stack Overflow or respective owner

Related posts about java