Slider Names

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page

Answer:

sliderV.addChangeListener( this ); 

Slider Names

There may be several sliders in your user interface. They all generate change events. If one change listener listens to all these events it is convenient to give the sliders names so that the events can be sorted out correctly. (Another way is to register its own listener with each slider). A name is a string that can be assigned to any object that inherits from class Component. Assign it using:

component.setName( String name )

Of course you must make sure that components that share the same listener have unique names.

QUESTION 9:

Assign names to the two sliders.

sliderA = new JSlider( JSlider.HORIZONTAL, 0, 1000, 400);
sliderB = new JSlider( JSlider.HORIZONTAL, 0, 1000, 400);
 . . . 
sliderA.setName(  ); 
sliderb.setName(  ); 

sliderA.addChangeListener( this ); 
sliderB.addChangeListener( this );