This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have a program where I need to add a new item to an array or modify an existing item and the user has to enter in the information. Most of the information is strings, so It doesnt matter what the user enters but two values need to be specific or I get an error message. I need an Integer and a Double. Here is the snippets of code that I am using right now for the logic, and it works perfectly if the user enters what they should enter...
Now there are more boxes above them as it is a big nested if statements going through single boxes at a time. I know I could maybe change everything to a textfield and ask for all the information at once, but the instructor for out class has provided us with examples that look like this instead and I am trying to stay true to the concept of the assignment.
So my question is, how would I check what the user enters here and make sure they are of the right value?
I get from that that I can set a specific action needed to close the window. But I honestly dont know how to use that to check if what the user entered was an int where required and a double where required. I apologize for my noobness, I am taking my first Java class ever and trying to learn quite a bit about its many functions.
The only section that I think would fit what Im trying to do is...
If i understand this, I would add this to my code and put in the values I was checking, and if they were not true, the window woudnt close. I would also need to make the changes to my frame class where it is set to exit on close now. But Even if I am right with my understanding here, I do not know how to tell it to check for an int value and then a double value.
Joined: Jun 13, 2009
I honestly dont know how to use that to check if what the user entered was an int where required and a double where required
See Integer.parseInt(...) and Double.parseDouble(...);