Change Listeners
To monitor slider input, you must have a class that implements the ChangeListener interface in the javax.swing.event package. This interface includes only one method:
public void stateChanged(ChangeEvent event); { // statements to handle the event}
To register an object as a change listener, call the addChangeListener(Object) method of the container that holds the slider. When the slider is moved, the listening object’s stateChanged() method is called.
This method is called with a ChangeEvent object that can identify the slider component that changed in value. Call the object’s getSource() method and cast the object to a JSlider, as in the following statement:
JSlider changedSlider = (JSlider) event.getSource();
In this example, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access