Action when user press "Cancel"

try{

String string_months = JOptionPane.showInputDialog("Enter number of months:");

// return if user press cancel.

months = Integer.valueOf(string_months).intValue();

}catch (NumberFormatException f){

JOptionPane.showMessageDialog(null,"Only numbers allowed!");

this.getInput();

}

This code will never terminate. Is there someway to catch if the user press cancel?

[673 byte] By [fedevapsa] at [2007-11-27 4:20:41]
# 1
Doesn't showInputDialog return null in that case?
Hippolytea at 2007-7-12 9:27:46 > top of Java-index,Java Essentials,Java Programming...
# 2
Print out the value of string_months after you get it from the JOptionPane. If it doesn't contain a number, (which it won't when the user presses cancel), then don't try to parse one out of it. Skip the call to this.getInput() and do whatever you want to do when the user presses
hunter9000a at 2007-7-12 9:27:46 > top of Java-index,Java Essentials,Java Programming...