import java.awt.BorderLayout; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.BoundedRangeModel; import javax.swing.JFrame; import javax.swing.JSlider; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; public class Main extends JFrame { JSlider slider = new JSlider(); BoundedRangeModel model = slider.getModel(); public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); getContentPane().add(slider, BorderLayout.CENTER); model.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { System.out.println("Value: " + model.getValue()); } }); pack(); setVisible(true); } public static void main(String arg[]) { new Main(); } }