aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Q: do I need to verify port number? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Q: do I need to verify port number?" Watch "Q: do I need to verify port number?" New topic
Author

Q: do I need to verify port number?

Andy Zhu
Ranch Hand

Joined: May 26, 2004
Posts: 145
I am trying to verify port number from gui input: it should be >0, an integer, and to some maximum number. As I understand, I can not use java bean package so that I can't use property change listener. How could I achieve this or I simply don't need to catch it?

Thanks


--------<br />Andy Zhu<br />scjp 1.4<br />scjd 1.4<br />SAS Certified Programmer 9.0
Anthony Watson
Ranch Hand

Joined: Sep 25, 2003
Posts: 327
You could create a class that implements javax.swing.text.PlainDocument and implement the insertString method to perform your validation. Then you would call setDocument on your port text field and pass it an instance of your new class. I used this technique to limit the number of characters that the user could enter into a text field. Hope that helped.
Anthony Watson
Ranch Hand

Joined: Sep 25, 2003
Posts: 327
The above method will validate every time the user tries to add text to a text field. However, you could also call a validation method only after the user hits the "connect" button.
Andy Zhu
Ranch Hand

Joined: May 26, 2004
Posts: 145
Hey, Anthony: thank you for help. I am not sure about your second reply: if a text field contains 123, when appending 4, will it validate one more time?

thanks.
Andy Zhu
Ranch Hand

Joined: May 26, 2004
Posts: 145
Hey, Anthony: find a simple solution in this case for this size of project. construct an Integer object which will throw NumberFormatException.

Cheer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Q: do I need to verify port number?