package com.mindprod.example;
import javax.swing.JFrame;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.SwingUtilities;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import static java.lang.System.*;
/**
* demonstrate the use of javax.swing.JSpinner.
*
* @author Roedy Green, Canadian Mind Products
* @version 1.0 2009-01-01 initial version
* @since 2009-01-01
*/
public final class TestJSpinner
{
/**
* Debugging harness for a Frame
*
* @param args command line arguments are ignored.
*/
public static void main( String args[] )
{
SwingUtilities.invokeLater( new Runnable()
{
/**
* fire up a JFrame on the Swing thread
*/
public void run()
{
final JFrame jFrame = new JFrame();
final Container contentPane = jFrame.getContentPane();
final JSpinner sizeSpinner = new JSpinner();
sizeSpinner.setBackground( Color.BLACK );
sizeSpinner.setForeground( Color.YELLOW );
sizeSpinner.setFont( new Font( "Dialog", Font.BOLD, 15 ) );
sizeSpinner.setEnabled( true );
Dimension d = new Dimension( 40, 25 );
sizeSpinner.setMinimumSize( d );
sizeSpinner.setPreferredSize( d );
sizeSpinner.setMaximumSize( d );
final SpinnerNumberModel sizeSpinnerModel =
new SpinnerNumberModel( 18,
8,
72,
1 );
sizeSpinner.setModel( sizeSpinnerModel );
sizeSpinner.addChangeListener( new ChangeListener()
{
/**
* Invoked when the JSpinner changes, even one notch in
* moving to another value
* @param e a ChangeEvent object
*/
public void stateChanged( ChangeEvent e )
{
float setting = sizeSpinnerModel.getNumber().floatValue();
out.println( setting );
}
} );
contentPane.add( sizeSpinner );
jFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
jFrame.pack();
jFrame.setVisible( true );
}
} );
}
}