943,603 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 488
  • Java RSS
Nov 14th, 2008
0

question on java

Expand Post »
I add integer values in combo box.When I call getSselectedItem it return object.How i convert it into integer.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kdhanshree is offline Offline
5 posts
since Nov 2008
Nov 14th, 2008
0

Re: question on java

I assume you are after JavaScript, not Java. Anyway with JavaScript values are not strongly typed, so if the values are numbers, you can use "+".
Reputation Points: 85
Solved Threads: 64
Practically a Master Poster
sillyboy is offline Offline
686 posts
since Mar 2007
Nov 14th, 2008
0

Re: question on java

Click to Expand / Collapse  Quote originally posted by kdhanshree ...
I add integer values in combo box.When I call getSselectedItem it return object.How i convert it into integer.
casting it to an Integer. but from your question I take it you want an int, and not an Integer.
so, cast it to a String, and parse that to an int.

for instance, you get back an Object with value = "6";

Java Syntax (Toggle Plain Text)
  1. public int objectToInt(Object givenObject){
  2. String inString = (String)givenObject;
  3. return Integer.parseInt(inString);
  4. }

't voila, instant integer-value. this will only work if the value stored in the object is a valid integer value, so if you have any other data in that list, you may want to catch possible exceptions.
Reputation Points: 919
Solved Threads: 354
Nearly a Posting Maven
stultuske is online now Online
2,474 posts
since Jan 2007
Nov 14th, 2008
0

Re: question on java

If you added the items as Integer objects:
java Syntax (Toggle Plain Text)
  1. int selectedValue = ((Integer)comboBox.getSelectedItem()).intValue();
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 838
Posting Genius
Ezzaral is offline Offline
6,756 posts
since May 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: How would you go about coding this?
Next Thread in Java Forum Timeline: Java FTP Server





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC