3

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.

2 Answers 2

2

You are creating a loop in the 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.

I would remove the while(true) loop.

Sign up to request clarification or add additional context in comments.

Comments

0

Try removing the while(true) statement. It shouldn't be necessary in your case.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.