Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.awt.Dimension;

import java.awt.Font;

import javax.swing.JSlider;

public class Main {
    public static JSlider getSlider(int w, int h, String name, int minValue, int maxValue) {
        JSlider slider = new JSlider(JSlider.HORIZONTAL, minValue, maxValue, ((maxValue + minValue) / 2));
        slider.setFont(getFont());
        slider.setPreferredSize(getSliderDimension(w, h));
        slider.setMinimumSize(getSliderDimension(w, h));
        slider.setName(name);
        return slider;
    }

    public static JSlider getSlider(int w, int h, String name, int minValue, int maxValue, int initValue) {
        JSlider slider = new JSlider(JSlider.HORIZONTAL, minValue, maxValue, initValue);
        slider.setFont(getFont());
        slider.setPreferredSize(getSliderDimension(w, h));
        slider.setMinimumSize(getSliderDimension(w, h));
        slider.setName(name);
        return slider;
    }

    public static Font getFont() {
        return new Font("Arial", Font.PLAIN, 10);
    }

    private static Dimension getSliderDimension(int w, int h) {
        return new Dimension(w, h);
    }
}