e800. 监听JSlider的数值变化

时间:2024-05-27 15:03:57
// Create horizontal slider
JSlider slider = new JSlider(); // Register a change listener
slider.addChangeListener(new ChangeListener() {
// This method is called whenever the slider's value is changed
public void stateChanged(ChangeEvent evt) {
JSlider slider = (JSlider)evt.getSource(); if (!slider.getValueIsAdjusting()) {
// Get new value
int value = slider.getValue();
}
}
});
Related Examples