Change Listeners
To monitor the use of a slider in a Java program, you must have a class that implements the ChangeListener interface, which is part of the javax.swing.event package of classes. This interface includes only one method, which takes the following form:
public void stateChanged(ChangeEvent evt) { // 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 will be called.
This method is called with a ChangeEvent object that can be used to identify the slider component that was changed in value. Call the object's getSource() method and cast the object to a JSlider ...
Get SAMS Teach Yourself Programming with Java™ in 24 Hours, FOURTH EDITION now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.