• 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

Reading out JSpinner

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving this to the Swing / AWT / SWT / JFace forum...
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for your reply, but i got it by myself before

bye
Constanze
reply
    Bookmark Topic Watch Topic
  • New Topic