Results 1 to 6 of 6
  1. #1
    mayhewj7 is offline Member
    Join Date
    Dec 2008
    Posts
    39
    Rep Power
    0

    Default 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.

  2. #2
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    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);"

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Seems you have no idea about this. showInputDialog() returns a string anyway. If the input is a number then you need the following.

    Java Code:
    int find = Integer.parseInt(s);
    If the input is a string on the message box, s returns a String object.

  4. #4
    kaemonsaionji is offline Member
    Join Date
    Feb 2009
    Posts
    9
    Rep Power
    0

    Default

    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.

  5. #5
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default

    here I have some comments:
    What would be the correct way for doing this if I had a String such as a name?
    You already have in your code:
    Java Code:
    [B][COLOR="Blue"]String s[/COLOR][/B] = JOptionPane.showInputDialog(null, "Enter Employee ID to search: ");
    JOptionPane.showInputDialog returns a string

    Now for kaemonsaionji comments:
    just remove the Integer.parseInt(s);
    agreed...
    its useless to your program just use a search statement to know if the entered employee id is existing or not...
    huh? I don't understand. How did you understand that from the info the OP gave?
    note: you can't compare strings in java, just make use of boolean instead.
    Huh again? That is not true. Sure you can compare strings. What do you mean with the boolean comment?
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

    Default

    > huh? I don't understand. How did you understand that from the info the OP gave?
    Probably because the button's variable identifier is searchButton, but as it's obvious that code has been copied without understanding any of it, that too doesn't mean anything ;)

    db

Similar Threads

  1. JOptionPane
    By Mir in forum New To Java
    Replies: 5
    Last Post: 11-29-2008, 02:04 AM
  2. JOptionPane
    By whosadork in forum New To Java
    Replies: 2
    Last Post: 10-23-2008, 02:17 AM
  3. JOptionPane problem
    By MomenT in forum New To Java
    Replies: 22
    Last Post: 10-02-2008, 05:56 PM
  4. JOptionPane (customizing)
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-14-2008, 11:39 AM
  5. Problem with JOptionPane.showInputDialog()
    By romina in forum AWT / Swing
    Replies: 1
    Last Post: 08-07-2007, 05:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •