Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

converting objects into strings...

 
Ron Sibayan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,
I was just wondering if anyone had any suggestions on the best way to go about converting an object into a string? the object is being generated by an ActionEvent linked to a JComboBox selection. ie I have a JComboBox which holds 5 possible options (1-5).
As far as I can tell (which probably isn't that far), the only way I can get the selected option is to use the getSelectedItem() method, however I need to use the outcome as an argument for another method which requires a string.

should I be using a diferent enquiry method to retreive the comboBox selection, or should I convert it once the object is out?

Ron Sibayan
 
Ruben Steins
Greenhorn
Posts: 15
Chrome IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does this work? The toString() method is inherited from Object, isn't it?

[ January 07, 2004: Message edited by: Ruben Steins ]
 
Wayne L Johnson
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since it is very possible that you'd want to do other things to the selected object, I'd leave the "getOrderInput()" method alone (i.e., have it return to selected object itself).
If you need to pass a string to some method, call the "getOrderInput()" method and then convert it to a String. If you are going to use the "toString()" method, make sure you override it the appropriate class so it returns a relevant value.
 
Ron Sibayan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys, youve been a big help
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic