Appendix B. Solutions
Figure B.9. In this design, components that depend on the slider implement
ChangeListener so that they can register for slider events.
SOLUTION 9.3.......................................................................................................................................
One solution is:
package com.oozinoz.applications;
import javax.swing.;
import java.util.;
import com.oozinoz.ballistics.Tpeak;
public class BallisticsLabel extends JLabel
implements Observer
{
public BallisticsLabel(Tpeak tPeak)
{
tPeak.addObserver(this);
}
public void update(Observable o, Object arg)
{
setText("" + ((Tpeak) o).getValue());
repaint();
}
}
Note that this solution places the Tpeak class in the ballistics package and
the BallisticsLabel class in the applications package.