Appendix H Elevator Model (on CD) 1421 14 (Bulletproof web design)

Appendix H Elevator Model (on CD) 1421 14 15 // manages Elevator thread 16 private boolean elevatorRunning = false; 17 18 // describes Elevator state (idle or moving) 19 private boolean moving = false; 20 21 // current Floor 22 private Location currentFloorLocation; 23 24 // destination Floor 25 private Location destinationFloorLocation; 26 27 // Elevator needs to service other Floor 28 private boolean summoned; 29 30 // listener objects 31 private Set elevatorMoveListeners; 32 private ButtonListener elevatorButtonListener; 33 private DoorListener elevatorDoorListener; 34 private BellListener bellListener; 35 36 // Door, Button and Bell on Elevator 37 private Door elevatorDoor; 38 private Button elevatorButton; 39 private Bell bell; 40 41 public static final int ONE_SECOND = 1000; 42 43 // time needed to travel between Floors (5 seconds) 44 private static final int TRAVEL_TIME = 5 * ONE_SECOND; 45 46 // max travel time for Elevator (20 minutes) 47 private static final int MAX_TRAVEL_TIME = 48 20 * 60 * ONE_SECOND; 49 50 // Elevator’s thread to handle asynchronous movement 51 private Thread thread; 52 53 // constructor creates variables; registers for ButtonEvents 54 public Elevator( Floor firstFloor, Floor secondFloor ) 55 { 56 setLocationName( ELEVATOR_NAME ); 57 58 // instantiate Elevator’s Door, Button and Bell 59 elevatorDoor = new Door(); 60 elevatorButton = new Button(); 61 bell = new Bell(); 62 63 // register Elevator for BellEvents 64 bell.setBellListener( this ); 65 Fig. H.12 Class Elevatorrepresents the Elevatortraveling between two Floors, operating asynchronously with other objects (part 2 of 9).
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.

Leave a Reply