package framework; import javax.swing.*; import javax.swing.event.*; import java.awt.event.*; import java.awt.*; import java.util.*; /** The base class for all views.

Programmers should extend this class with any panel that displays the model.

Example:

     class PieChartView extends AppView {
        public PieChartView(MyModel m) {
	       super(m);
	       display();
	    }
	    public void update(Observable o, Object arg) {
	       display();
	    }
	    private void display() {
	       MyModel m = (MyModel)model;
	       // draw a pie chart of the data in m
	    }
    }
    
*/ public class AppView extends JPanel implements Observer { /** The model that this view displays */ protected Model model; /** Initializes model. Adds this view as an observer to the new model and deletes it as an observer to the previous model. @param m the new model */ public AppView(Model m) { setModel(m);; } /** This does not initialize the model. Programmers must call setModel. */ public AppView() { } /** Sets the model to a new model. Deletes this view from the observers of the old model. Adds this view to the observers of the new model. @param m The new model */ public void setModel(Model m) { if (model != null) { model.deleteObserver(this); } model = m; model.addObserver(this); } /** This method is indirectly called by Model.notifyViews.

The implementation is empty. Programmers should override this method in subclasses so that it fetches new data from the model and redraws the view. */ public void update(Observable o, Object arg) { } }