• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do I parse a String?  RSS feed

 
Ryan Bishop
Ranch Hand
Posts: 143
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm learning about inheritance and on this problem I first have to create a class where I get/set methods and get user input for the data fields.
I suppose I should know it at this point but I don't know how to get the users name when they input it. I copied the whole code but
the issue is at line 51.

Thanks.

 
Knute Snortum
Sheriff
Posts: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the problem?
 
Scott Winterbourne
Ranch Hand
Posts: 116
2
Eclipse IDE Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm no Swing expert but I think JOptionPane.ShowInputDialog() returns a String. Your "customerNameString" variable will contain whatever String the user entered. What do you need to parse from the input?

See the Documentation for this component and method.
 
Campbell Ritchie
Marshal
Posts: 56576
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is more about option panes in the Java Tutorials.
SW is right: if you enter Ryan Bishop in the option pane it will return Ryan Bishop as a String.
Don't write new String(...). Simply write.
String name = JOptionPane.showInputDialog(...);


Of course there is something else. You are not using the String for anything. I presume that is the next stage?

Why are you using option panes? That is very old‑fashioned programming. Find out about Scanner.
 
Ryan Bishop
Ranch Hand
Posts: 143
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the replies. A little while later I realized I didn't have to parse it.

I'm not sure why I'm using joptionpane but I'm not sure about anything I do with java. The book I'm using just says to get "get user input" but in the chapter shows examples with joptionpane. I'm thinking I may just change it to scanner.

Just out of curiosity, why is it old fashioned? Is scanner more efficient in some way?
 
David McMonigle
Greenhorn
Posts: 24
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually JOptionPane can be very useful when getting quick little tidbits from the user. I use it whenever something might be missing on a userform or something like that.



That's a good example to use when using JOptionPane.
 
Campbell Ritchie
Marshal
Posts: 56576
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But that is a different scenario from what we have here.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!