• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

converting objects into strings...

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 15
IntelliJ IDE Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys, youve been a big help
reply
    Bookmark Topic Watch Topic
  • New Topic