3
由于某种原因,这是锁定了Java应用程序。我是否正确处理异常?Java Swing应用程序的异常?
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返回到java应用程序。
谢谢,就是这样。 – 2010-05-30 00:37:11