MainClass.java Source code

Java tutorial

Introduction

Here is the source code for MainClass.java

Source

import java.awt.BorderLayout;
import java.util.List;

import javax.swing.JFrame;
import javax.swing.JSpinner;
import javax.swing.SpinnerListModel;
import javax.swing.SpinnerModel;

public class MainClass {

    public static void main(final String args[]) {
        JFrame frame = new JFrame("JSpinner Dates");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        SpinnerModel model3 = new RolloverSpinnerListModel(new String[] { "a", "b", "c" });
        JSpinner spinner3 = new JSpinner(model3);

        frame.add(spinner3, BorderLayout.SOUTH);

        frame.setSize(200, 90);
        frame.setVisible(true);

    }

}

class RolloverSpinnerListModel extends SpinnerListModel {

    public RolloverSpinnerListModel(List<?> values) {
        super(values);
    }

    public RolloverSpinnerListModel(Object[] values) {
        super(values);
    }

    public Object getNextValue() {
        Object returnValue = super.getNextValue();
        if (returnValue == null) {
            returnValue = getList().get(0);
        }
        return returnValue;
    }

    public Object getPreviousValue() {
        Object returnValue = super.getPreviousValue();
        if (returnValue == null) {
            List list = getList();
            returnValue = list.get(list.size() - 1);
        }
        return returnValue;
    }
}