1416 Elevator Model (Disney web site) (on CD) Appendix H 265 293
Wednesday, November 21st, 20071416 Elevator Model (on CD) Appendix H 265 293 provide methods allowing objects to register themselves as listeners for various events. The constructor (lines 37 166) instantiates listener objects from several inner classes these listener objects receive events from other objects, then re-send the events to the listener objects defined in line 30 34. For example, lines 43 60 declare a ButtonListenerobject called floorButtonListener, which contains the logic for when a Button on a Floorhas been pressed or reset. Lines 63 70 instantiate firstFloorButtonand secondFloorButton, then register floorButtonListener as a ButtonListener for both Button objects. When either Button has been pressed, that Button invokes method buttonPressed (lines 47 53) of the floorButtonListener. When either Button has been reset, that Button invokes the floorButtonListener s method buttonReset (lines 56 59). Method buttonPressed requests the Elevator by invoking the Elevator s method requestElevator method buttonPressed passes a Location reference of the Floor that generated the ButtonEvent. Both methods buttonPressed and buttonReset send the ButtonEvent to the ButtonListenerdefined in line 31 (which, in this case, is ElevatorModel). Lines 77 92 declare a DoorListener object called floorDoorListener, which contains the logic for when a Dooron a Floorhas opened or closed. Lines 95 100 instantiate firstFloorDoorand secondFloorDoor, then register floorDoorListener as a DoorListener for both Door objects. When either Door has opened, that Door calls method doorOpened (lines 80 84) of the floorDoorListener. When either Doorhas closed, that Doorcalls method doorClosed(lines 87 91) of the floorDoorListener. Both methods send the DoorEvent to the DoorListener declared in line 30 (which, in this case, is ElevatorModel). Lines 112 115 instantiate the Elevator and register the ElevatorShaft as an ElevatorMoveListener with the Elevator. When the Elevator has departed, the Elevator invokes method elevatorDeparted (lines 229 243), which informs all objects in elevatorMoveListeners of the departure. When the Elevator has arrived, the Elevator invokes method elevatorArrived (lines 246 262), which informs all objects in elevatorMoveListenersof the arrival. H.7 Classes Lightand Bell Class Light (Fig. H.10) represents the Lights on the Floors in the model. Objects of classes Light help decorate the view by sending events to the ElevatorViewvia the bubble up technique described previously. In our simulation, the ElevatorViewturns on and off the Light in the view upon receiving a lightTurnedOn or light- TurnedOffevent, respectively. // Light.java // Light turns a light on or off package com.deitel.jhtp4.elevator.model; // Deitel packages import com.deitel.jhtp4.elevator.event.*; Fig. H.10 Class Lightrepresents a Lighton the Floorin the model (part 1 of 3).
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.