![]() |
![]() |
![]() |
![]() |
![]() |
|
You solve the undefined-variable problem by
making your application instance available to methods defined in the
MovieObserver class. You make that application instance available
in a three-step idiom:
The following illustrates. Both the meter and the movie become accessible
via the value of the applet variable.
import java.util.*;
public class MovieObserver implements Observer {
private MovieApplication applet;
public MovieObserver (MovieApplication a) {
applet = a;
}
public void update (Observable observable, Object object) {
applet.getMeter().setValue(applet.getMovie().rating());
applet.getMeter().setTitle(applet.getMovie().getTitle());
}
}