import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class SimpleSliderDemo extends JFrame {
private JSlider slider;
private JTextField txtValue;
public SimpleSliderDemo() {
super ("JSlider Sederhana");
Container container = getContentPane();
container.setLayout(new FlowLayout());
txtValue = new JTextField (20);
txtValue.setBackground(Color.WHITE);
txtValue.setEditable(false);
slider = new JSlider(SwingConstants.HORIZONTAL,0,100,50);
txtValue.setText(String.valueOf(slider.getValue()));
slider.setMinorTickSpacing(5);
slider.setMajorTickSpacing(20);
slider.setPaintTicks(true);
slider.setLabelTable(slider.getLabelTable());
slider.setPaintLabels(true);
slider.addChangeListener (
new ChangeListener() {
public void stateChanged (ChangeEvent e) {
txtValue.setText ( String.valueOf(slider.getValue()) );
}
}
);
container.add(txtValue);
container.add(slider);
setSize (280,200);
setVisible (true);
}
public static void main (String args[]) {
JFrame.setDefaultLookAndFeelDecorated(true);
SimpleSliderDemo test = new SimpleSliderDemo();
test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}