question on java

Reply

Join Date: Nov 2008
Posts: 5
Reputation: kdhanshree is an unknown quantity at this point 
Solved Threads: 0
kdhanshree kdhanshree is offline Offline
Newbie Poster

question on java

 
0
  #1
Nov 14th, 2008
I add integer values in combo box.When I call getSselectedItem it return object.How i convert it into integer.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 686
Reputation: sillyboy is on a distinguished road 
Solved Threads: 61
sillyboy's Avatar
sillyboy sillyboy is offline Offline
Practically a Master Poster

Re: question on java

 
0
  #2
Nov 14th, 2008
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 "+".
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 706
Reputation: stultuske is a jewel in the rough stultuske is a jewel in the rough stultuske is a jewel in the rough 
Solved Threads: 84
stultuske's Avatar
stultuske stultuske is offline Offline
Master Poster

Re: question on java

 
0
  #3
Nov 14th, 2008
Originally Posted by kdhanshree View Post
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";

  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.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,427
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 507
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: question on java

 
0
  #4
Nov 14th, 2008
If you added the items as Integer objects:
  1. int selectedValue = ((Integer)comboBox.getSelectedItem()).intValue();
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC