Catch Negative Number
843789Oct 5 2009 — edited Oct 5 2009Hi experts,
Is anyone can teach me how to catch negative input in GUI. I use NumberFormatException but it only catches String. I'd like to know in either way (try-catch and throwing exception.
private void btnEnterActionPerformed(java.awt.event.ActionEvent evt)
{
String amount = txtAmount.getText();
if(!amount.equals(null) && !amount.equals(""))
{
try
{
double balance = depositTransaction.deposit(Double.parseDouble(this.txtAmount.getText()));
lblBalance.setText("Your account balance is: $" + balance);
}
catch(NumberFormatException e)
{
lblBalance.setText("Invalid deposit entry");
}
txtAmount.setText("");
btnEnter.setEnabled(false);
}
}
Thanks heaps.