Change Events


Introduction.  Now we need to introduce another user event listener that focuses on changes in GUI controls.

When we work with things like sliders and scrollbars we need to be able to code so that the program will be able to respond to user inputs.  This is most typically done with change events

In order to make use of change events a class must implement the ChangeListener interface.  This is somewhat analogous to implementing the ActionListener and ItemListener we have worked with in earlier sections.

There  is only one method within this interface that will be invoked by a programmer to respond to when a user interacts with a control that implements an ChangeListener.  The method is outlined in the following table.


Method Description
void stateChanged(ChangeEvent evt) This is the method that must be developed by the programmer to respond to user actions with controls that have ChangeListeners.


To determine which item/control was actually used by the user there is one primary built-in method that the programmer might use.


Method Description
getSource( ) This is used to determine in which item the change event occurred.  For example, this can happen if you have more than one slider.
getValue( ) This is used to get the value of the JSlider that is being changed.