Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.awt.BorderLayout;
import java.awt.Container;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.JTextField;
import javax.swing.SpinnerNumberModel;

public class Main {
    public static void main(String args[]) {
        SpinnerNumberModel model = new SpinnerNumberModel(0.0, -1000.0, 1000.0, 0.1);
        JSpinner s = new JSpinner(model);
        JSpinner.NumberEditor editor = new JSpinner.NumberEditor(s);
        s.setEditor(editor);
        JTextField stepText = new JTextField(10);
        JButton bStepSet = new JButton("Set Step");
        bStepSet.addActionListener(e -> {
            Double val = Double.parseDouble(stepText.getText().trim());
            model.setStepSize(val);
        });
        JFrame f = new JFrame();
        Container c = f.getContentPane();
        c.add(s);
        JPanel southPanel = new JPanel();
        southPanel.add(stepText);
        southPanel.add(bStepSet);
        c.add(southPanel, BorderLayout.SOUTH);
        f.pack();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setVisible(true);
    }
}