Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading out JSpinner

 
Constanze Michaelis
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi @ all!

I am writing an applet where I use JSpinners to get user entries. now I don't know how to read them out into an integer variable.

thanks in advance
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question would probably be more appropriate in the GUI forum. However, I'll still try to answer it here. If you look at the API docs for JSpinner, you will see that it has a getValue() method to return the current value. This method returns an Object, but you can cast it to the type that you expect. If you are using SpinnerNumberModel in the JSpinner, then you can cast this Object from JSpinner.getValue() to an Integer. From there, you can get an int from the Integer object using its intValue() method.

With that said, I strongly suggest that you familiarize yourself with the Java API docs. Although I had a vague idea how to answer your question, I still had to use the API docs to look up the details of the above description. They are an invaluable tool when you are programming Java as it is nearly impossible to memorize every method in every class that is available in the standard API.

Keep Coding!

Layne
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Swing / AWT / SWT / JFace forum...
 
sasi kala
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use ChageListener // javax.swing.event.ChangeListener


class .. implements ChageListener
{
......
jSpinner1.addChangeListener(this);
.........

public void stateChanged(javax.swing.event.ChangeEvent evt)
{
Integer i = new Integer(jSpinner1.getValue().toString());
int value = i.intValue();
......
}

}

All The Best
 
Constanze Michaelis
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your reply, but i got it by myself before

bye
Constanze
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic