Could you please clarify? Are you trying to verify the data type? The value and range? Do you only have one JTextField for different types of input? (Please note that by definition a JTextField data is text; you need to parse the text to get numerical information.)
Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
Joined: May 25, 2004
Ok, there's a dialog, based on the type that I choose, the type could be an int, a decimal, a boolean, etc. based on the type I chose, I need to verify the input that the user enters in the JTextField. Btw, the input in a JTextField is a text instead of a String? Maybe if there is an alternative component that I can use to simplify this?
I'm stil not exactly clear what you are attempting here.
Are you saying that you choose your data type AND THEN pop up a dialog based on your choice?
If so, then you already know the data type that will be represented by the text in your dialog text fied.
Joined: Jul 30, 2003
The getText method returns a String object, which is one of Java's implementations of text. If you want the user to enter an integer, and you want to validate the integer entered, you would have to parse the String returned from the JTextField using a try-catch block which would catch a NumberFormatException if the value you're trying to parse as an int is not in the range of an int.
If that doesn't help clarify, then please post a snippet of pseudocode to show what you're trying to accomplish and maybe we can help from that. If you do post pseudocode or actual code, please use the UBB CODE tags to help with readability.
Joined: May 25, 2004
Thanks a lot! I think the last message is what I'm trying to do: the user first chooses the type, then the user enter the value, based on the type (int, decimal, string, boolean, percent, or any other type the user could define with ranges), we will verify the validation of the value just entered.
Step1: the user chooses a type called LimiteInteger [0~1]; Step2: the user enters 2.0 in the JTextField Step3: the user pushes the button "Accept" Step4: Error Message poped up.