1428 Elevator Model (on CD) Appendix H 372
1428 Elevator Model (on CD) Appendix H 372 } 373 } Fig. H.12 Class Elevatorrepresents the Elevatortraveling between two Floors, operating asynchronously with other objects (part 9 of 9). According to Fig. H.2, class Elevatorimplements interfaces ButtonListener, DoorListener and BellListener and therefore can listen for ButtonEvents, DoorEvents and BellEvents. Class Elevator must send these events to a listener (in this case, the ElevatorShaft), so that these events can bubble up to the ElevatorView. Class Elevator contains a ButtonListener called elevatorButtonListener (line 32), a DoorListener called elevatorDoorListener (line 33) and a BellListenercalled bellListener(line 34). Lines 269 284 list methods setButtonListener, setDoorListenerand setBellListenerthat allow an object such as ElevatorShaft to register as a listener for these events. Class Elevatorcontains an anonymous ButtonListener(lines 84 106) that registers for ButtonEvents from the elevatorButton. When a Personhas pressed the elevatorButton, the ButtonListenercalls method buttonPressed (lines 88 96) of the ButtonListener. Lines 91 92 of this method call method buttonPressed of the elevatorButtonListener, and line 95 informs the Elevatorto move using method setMoving. When the Button has been reset, the ButtonListener calls method buttonReset (lines 99 104) of the ButtonListener. Lines 102 103 of this method calls method buttonResetof the elevatorButtonListener. Class Elevatorcontains an anonymous DoorListener(lines 110 145) that registers for DoorEvents from the elevatorDoor. When the elevatorDoor has opened, the DoorListenercalls method doorOpened(lines 114 127) of this Door- Listener. Lines 121 122 open the Door on the Floor that generated the event, and lines 125 126 call method doorOpened of the elevatorDoorListener. Method doorOpened guarantees that the Door on the Floor opens before the passenger exits the Elevator. When the elevatorDoor has closed, the DoorListener calls method doorClosed(lines 130 143) of the DoorListener. Lines 137 138 close the Door on the Floor that generated the event, and lines 141 142 call method door- Closedof the elevatorDoorListener. Class Elevatoracts as a thread because it implements interface Runnable. Method run(lines 173 204) handles the travel between Floors. The method begins with the Elevatorremaining idle in a whileloop (lines 178 179). The loop exits when method buttonPressedin the anonymous ButtonListenercalls method setMoving. When the Elevator exits the loop, the Elevator closes the elevatorDoor (line 182) then calls private method sendDepartureEvent (lines 316 333), to inform all listeners the elevatorButton, the elevatorDoor, the bell and the ElevatorShaft of the Elevator s departure. Class Elevator contains Set elevatorMoveListeners (line 31), which stores all registered Elevator- MoveListeners. Objects wishing to receive ElevatorMoveEvents from the Elevator must call method addElevatorMoveListener (lines 262 266), which appends that object to elevatorMoveListeners. Method sendDepartureEvent invokes method elevatorDeparted of each listener object in Set elevator- MoveListeners.
From our experience, we can recommend PHP5 Web Hosting services, if you need affordable webhost to host and run your web application.