File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Q: do I need to verify port number?

 
Andy Zhu
Ranch Hand
Posts: 145
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Anthony Watson
Ranch Hand
Posts: 327
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 327
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 145
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 145
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic