package slider; import javax.swing.*; import java.awt.event.*; import slider.*; // This view registers the window with the model and delegates change // notification calls from the model to the slider view. At the end of // Olsen, Chapter 6, different techniques for determining when to save the // model are discussed. This technique // of registering the window with the model illustrates how the second // technique for saving the model can be implemented. public class SliderGraphicalView extends JFrame implements SliderView { // Declare instance variables SliderModel model; Slider slider; // Define constructor public SliderGraphicalView(SliderModel m) { super("Slider Application"); model = m; model.addObserver(this); slider = new Slider(model); // all components should be added to the content pane getContentPane().add("Center", slider); // setDefaultCloseOperation tells Java what to do when the close button // in the main window is pressed setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // calculate the size of the frame and layout its subcomponents pack(); // display the frame setVisible(true); } public void valueChanged(int oldValue) { slider.valueChanged(oldValue); } public void titleChanged(String oldTitle) { slider.titleChanged(oldTitle); } }