try catch issue

i have a jtext feild which the user have to insert a number in it , i applied a try and catch block to catch the exception when the user don't enter any thing, but the program continue..what i need is to stop until the user insert a number.

try{

if(!num.getText().equals(null)){

i=Integer.parseInt(num.getText());

}else{i=0;

}}catch(Exception e){

JOptionPane.showMessageDialog(null,"Insert the maximun number");

}

[861 byte] By [student14a] at [2007-11-27 2:41:27]
# 1

> i have a jtext feild which the user have to insert a

> number in it , i applied a try and catch block to

> catch the exception when the user don't enter any

> thing, but the program continue..what i need is to

> stop until the user insert a number.

>

> try{

>if(!num.getText().equals(null)){

> i=Integer.parseInt(num.getText());

>

> }else{i=0;

>

> }}catch(Exception e){

> JOptionPane.showMessageDialog(null,"Insert the

> he maximun number");

>

> }

i don't have much idea about Swing but does JTextField through an exception if user does not enter anything

if not then u need to manually throw an exception and then catch if this is the case then subclass the Exception class and create ur own Exception .

gaurav_xmla at 2007-7-12 3:05:16 > top of Java-index,Java Essentials,New To Java...
# 2
the exception is throwed correctly but the programm continue by the default value of the textfield , so i want it to go back to the textfeild to let the user enter a correct value.
student14a at 2007-7-12 3:05:16 > top of Java-index,Java Essentials,New To Java...
# 3

The problem seems to be in the code that surrounds or calls the try/catch you posted. Iif you detect that a textfield does not contain a "legal" value, you should possibly notify the user and the caller should abort doing whatever it was that it was trying to do with the field's value. Having a "default value" seems to be getting in the way here.

pbrockway2a at 2007-7-12 3:05:16 > top of Java-index,Java Essentials,New To Java...