Java SpinnerNumberModel extend

Description

Java SpinnerNumberModel extend

import java.awt.Color;
import java.awt.FlowLayout;

import javax.swing.JFrame;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
class GrayModel extends SpinnerNumberModel {
   public GrayModel(int value) {
     super(value, 0, 255, 5);
   }/*from   w w  w .jav a  2 s.  co m*/

   public int getIntValue() {
     Integer myValue = (Integer) getValue();
     return myValue.intValue();
   }

   public Color getColor() {
     int intValue = getIntValue();
     return new Color(intValue, intValue, intValue);
   }
 }
public class Main extends JFrame {
   public Main() {
      super("java2s.com");

      setDefaultCloseOperation(EXIT_ON_CLOSE);
      setLayout(new FlowLayout());


      SpinnerNumberModel m_numberSpinnerModel = new GrayModel(50);
      JSpinner spinner = new JSpinner(m_numberSpinnerModel);
      
      getContentPane().add(spinner);
   }

   public static void main(String[] args) {
      Main frame = new Main();
      frame.pack();
      frame.setVisible(true);
   }
}



PreviousNext

Related