Results 1 to 6 of 6
Thread: JOptionPane.showInputDialog
- 02-24-2009, 05:39 AM #1
Member
- Join Date
- Dec 2008
- Posts
- 39
- Rep Power
- 0
JOptionPane.showInputDialog
if(searchButton == e.getSource()){
String s = JOptionPane.showInputDialog(null, "Enter Employee ID to search: ");
int find = Integer.parseInt(s);
I know this works when you want to input a number such as 1,2,3 and so on.
What would be the correct way for doing this if I had a String such as a name? The Interger.parseInt will not work for that? How do I go about this? Thanks.
- 02-24-2009, 06:10 AM #2
Senior Member
- Join Date
- Jan 2009
- Posts
- 671
- Rep Power
- 5
The question needs clarification. Are you trying to convert a name into a number? If not, then just take out the "int find = Integer.parseInt(s);"
- 02-24-2009, 08:21 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Seems you have no idea about this. showInputDialog() returns a string anyway. If the input is a number then you need the following.
If the input is a string on the message box, s returns a String object.Java Code:int find = Integer.parseInt(s);
- 02-25-2009, 01:38 AM #4
Member
- Join Date
- Feb 2009
- Posts
- 9
- Rep Power
- 0
just remove the Integer.parseInt(s); its useless to your program just use a search statement to know if the entered employee id is existing or not...
note: you cant compare strings in java, just make use of boolean instead.
- 02-25-2009, 02:24 AM #5
here I have some comments:
You already have in your code:What would be the correct way for doing this if I had a String such as a name?
JOptionPane.showInputDialog returns a stringJava Code:[B][COLOR="Blue"]String s[/COLOR][/B] = JOptionPane.showInputDialog(null, "Enter Employee ID to search: ");
Now for kaemonsaionji comments:
agreed...just remove the Integer.parseInt(s);
huh? I don't understand. How did you understand that from the info the OP gave?its useless to your program just use a search statement to know if the entered employee id is existing or not...
Huh again? That is not true. Sure you can compare strings. What do you mean with the boolean comment?note: you can't compare strings in java, just make use of boolean instead.Chris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 02-25-2009, 06:04 AM #6
Similar Threads
-
JOptionPane
By Mir in forum New To JavaReplies: 5Last Post: 11-29-2008, 02:04 AM -
JOptionPane
By whosadork in forum New To JavaReplies: 2Last Post: 10-23-2008, 02:17 AM -
JOptionPane problem
By MomenT in forum New To JavaReplies: 22Last Post: 10-02-2008, 05:56 PM -
JOptionPane (customizing)
By Java Tip in forum Java TipReplies: 0Last Post: 03-14-2008, 11:39 AM -
Problem with JOptionPane.showInputDialog()
By romina in forum AWT / SwingReplies: 1Last Post: 08-07-2007, 05:33 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks