788 Graphical User Interface Components: Part (Apache web server tutorial) 2 Chapter
Tuesday, July 31st, 2007788 Graphical User Interface Components: Part 2 Chapter 13 32 33 // register View for Model events 34 model.setElevatorModelListener( view ); 35 36 // add view and controller to ElevatorSimulation 37 getContentPane().add( view, BorderLayout.CENTER ); 38 getContentPane().add( controller, BorderLayout.SOUTH ); 39 40 } // end ElevatorSimulation constructor 41 42 // main method starts program 43 public static void main( String args[] ) 44 { 45 // instantiate ElevatorSimulation 46 ElevatorSimulation simulation = new ElevatorSimulation(); 47 simulation.setDefaultCloseOperation( EXIT_ON_CLOSE ); 48 simulation.pack(); 49 simulation.setVisible( true ); 50 } 51 } Fig. 13.21 Class ElevatorSimulationis the application for the elevator simulation (part 2 of 2). The class diagram of Fig. 13.19 specifies that class ElevatorSimulation is a subclass of javax.swing.JFrame line 16 declares class ElevatorSimulation as a public class extending class JFrame. Lines 19 21 implement class Elevator- Simulation s aggregation of class ElevatorModel, the ElevatorView and the ElevatorController (shown in Fig. 13.19) by declaring one object from each class. Lines 29 31 of the ElevatorSimulationconstructor initialize these objects. Figure 13.19 and Fig. 13.20 specify that the ElevatorViewis an ElevatorModelListenerfor the ElevatorModel. Line 34 registers the ElevatorViewas a listener for ElevatorModelEvents, so the ElevatorViewcan receive events from the ElevatorModel and properly represent the state of the model. Lines 37 38 add the ElevatorView and the ElevatorController to the ElevatorSimulation. According to the stereotypes in Fig. 13.20, ElevatorSimulation.javacompiles to ElevatorSimulation.class, which is executable lines 43 50 provide method mainthat runs the application. We have completed the design of the components of our system. Thinking About Objects Section 15.12 concludes the design of the model by solving the interaction problems encountered in Fig. 10.26. Finally, Section 22.9 completes the design of the view and describes in greater detail how the ElevatorView receives events from the ElevatorModel. These last two sections will prepare you for the walkthrough of our elevator- simulation implementation in Appendices G, H and I. 13.18 (Optional) Discovering Design Patterns: Design Patterns Used in Packages java.awtand javax.swing We continue our discussion from Section 9.24 on design patterns. This section introduces those design patterns associated with Java GUI components. After reading this section, you
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.