1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Java GUI

  1. Nov 27, 2007 #1
    When using GUIs, you can enter an integer or a double into an input dialog box, then you can set a variable equal to the input such as below:

    int variable = Integer.parseInt(String name);

    or

    double variable = Double.parseDouble(String name);

    If I enter a string into the dialog box, and I want to set a variable of the string type equal to that input, what code can I use that's similar to the code above? I can't seem to find anything in my text book.

    I'm looking for something like: String variable = String.parseString(String name);

    Any help is appreciated.
     
  2. jcsd
  3. Nov 27, 2007 #2
    I'm not totally sure I understand the question, but I'm pretty sure that what you want is the

    object.toString()

    method.

    ANY object in Java should have a toString() method (although sometimes it will not return what you expect) and so it is analogous to the Type.parse(object) methods..
     
  4. Nov 28, 2007 #3

    HallsofIvy

    User Avatar
    Staff Emeritus
    Science Advisor

    I'm no expert on Java but I would think that the reason you NEED "Integer.parseInt(String name)" and "Double.parseDouble(String name)" is to change a string to an integer or double. You don't NEED a function to change a string to a string!

    Just "String variable= name;" should work.
     
  5. Nov 28, 2007 #4
    Thank you for the replies.

    I think HallsofIvy hit the nail on the head. I was doing it assbackwards. I should have imported a GUI package, and used the methods within that package to display a string.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Java GUI
  1. Vb.net\ Gui (Replies: 5)

  2. Cross-platform GUI (Replies: 5)

Loading...