Java Reference
In-Depth Information
CHALLENGE 9.4
Suppose that
tPeak
is an instance of
Tpeak
and an attribute of
the
ShowBallistics
class.
Complete
the
code
for
ShowBallistics.slider()
so that the slider's changes update
tPeak
.
public JSlider slider()
{
if (slider == null)
{
slider = new JSlider();
sliderMax = slider.getMaximum();
sliderMin = slider.getMinimum();
slider.addChangeListener
(
new ChangeListener()
{
??
}
);
slider.setValue(slider.getMinimum());
}
return slider;
}
When you apply MVC, the flow of events may seem indirect. Slider movement in
the ballistics application causes a
ChangeListener
to update a
Tpeak
object. In turn,
a change in the
Tpeak
object notifies the application's label and panels, and these objects
repaint themselves. Change propagates from the GUI layer to the business layer and back up
to the GUI layer.