Adding an instance of the new MovieData
model class produces the
following modification of the applet defined in
Segment 797.
import javax.swing.*; import java.awt.event.*; import java.util.*; public class MovieApplication extends JApplet { // Declare instance variables: private Meter meter; private Movie movie; private MovieData movieData; // Define constructor public MovieApplication() { // Create models getMovie(); getMovieData(); // Create and connect view to application getContentPane().add("Center", getMeter()); } // Define getters and setters public Meter getMeter () { if (meter == null) {setMeter(new Meter(0, 30));} return meter; } public Movie getMovie () { if(movie == null) {setMovie(new Movie (10, 10, 10, "On to Java"));} return movie; } public MovieData getMovieData () { if(movieData == null) {setMovieData(new MovieData ());} return movieData; } public void setMeter (Meter m) { meter = m; meter.addMouseListener(new MeterListener(this)); } public void setMovie (Movie m) { if(movie == m) {return;} if(movie instanceof Movie) {movie.deleteObservers();} if(m instanceof Movie) { movie = m; movie.addObserver(new MovieObserver(this)); movie.changed(); } } public void setMovieData (MovieData m) { movieData = m; } }