permaculture playing cards*
The moose likes Beginning Java and the fly likes empty input with JOptionPane (how to catch it ?).. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "empty input with JOptionPane (how to catch it ?).." Watch "empty input with JOptionPane (how to catch it ?).." New topic
Author

empty input with JOptionPane (how to catch it ?)..

mike ryan
Ranch Hand

Joined: Aug 08, 2010
Posts: 210

Hi all,

I have a question, i have a program where the user creates a box or more boxes, and they are saved during runtime only, in an Array.(that was how i had to write it for a project.).
no matter where in the program if i use an input dialog like---> and i press OK with nothing in the input box,all the boxes are deleted that where made?? My question is how do i catch it and get the user to re-input?I see with a String i can use if(id==null),but how do i do it with an integer?


Thanks
Mike
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Look at the javadoc and should be able to figure it out.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
mike ryan
Ranch Hand

Joined: Aug 08, 2010
Posts: 210

Thanks Wouter!!

I didn't think it would be that simple;), now just gotta figure out how to loop back to the input again..,This wasn't actually part of the project but i noticed it and wanted to correct it.
I hope we do exceptions next as that seems to be a very important part of programming, and there are tons of other errors that can eventually happen i suppose.

Mike
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

About the re-input question.

You can reverse the question to come up with the answer.

If you user inputs a wrong value ask again
Becomes
Stop asking the user for a value as soon as he enters a correct value.


mike ryan
Ranch Hand

Joined: Aug 08, 2010
Posts: 210

hi Wouter,

Yes i am using while(input==wronginput){try{, it just looks like i will have to re-do the loop a bit so after the catch(NumberFormatException) it goes back to it.Someone also wrote here that i shouldn't use continue; in a loop,

why is that exactly.Or what is the reasoning behind it?And if i don't use that then how else is it done?for instance if someone enters a "zero" and i have if(id==0){continue;}
and thanks once again for the help;)

Mike
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

The usage of break and continue should be discussed in another thread because a lot of people will have a strong opinion about it.
And you don't even have to use break:


Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38062
    
  22
And avoid == on reference types.
mike ryan
Ranch Hand

Joined: Aug 08, 2010
Posts: 210

Hi,

ok then i can just use boolean true;false; I was actually using a boolean and break;continue; ok then i will use that method!!


Thanks!
Mike

should i start another thread about the use of break and continue?

(although i just read via google , that a while statement MUST always have a break; ? )i suppose google isn't always your friend...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: empty input with JOptionPane (how to catch it ?)..
 
Similar Threads
Send Japanese Characters from JSP to Servlet
How to check if user has inputed all the fields in a form?
checking user input?how to go about it ?
Problem with indexing of an array
dynamically adding textboxes