Java GUI

  • #1
434
0
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.
 

Answers and Replies

  • #2
560
1
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..
 
  • #3
HallsofIvy
Science Advisor
Homework Helper
41,833
964
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.
 
  • #4
434
0
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.
 

Related Threads on Java GUI

  • Last Post
Replies
3
Views
2K
  • Last Post
Replies
8
Views
953
  • Last Post
Replies
5
Views
5K
  • Last Post
Replies
2
Views
1K
  • Last Post
Replies
5
Views
2K
Replies
2
Views
784
Replies
2
Views
10K
  • Last Post
Replies
8
Views
3K
  • Last Post
Replies
7
Views
3K
  • Last Post
2
Replies
41
Views
735
Top