Appendix H Elevator Model (on CD) 1417 8 (Tomcat web server)
Appendix H Elevator Model (on CD) 1417 8 public class Light implements ElevatorMoveListener { 9 // Light state (on/off) 11 private boolean lightOn; 12 13 // time before Light turns off automatically (3 seconds) 14 public static final int AUTOMATIC_TURNOFF_DELAY = 3000; 15 16 // LightListener listens for when Light should turn on/off 17 private LightListener lightListener; 18 19 // location where Light turned on or off private Location lightLocation; 21 22 // set LightListener 23 public void setLightListener( LightListener listener ) 24 { 25 lightListener = listener; 26 } 27 28 // turn on Light 29 public void turnOnLight( Location location ) { 31 if ( !lightOn ) { 32 33 lightOn = true; 34 35 // send LightEvent to LightListener 36 lightListener.lightTurnedOn( 37 new LightEvent( this, location ) ); 38 39 lightLocation = location; 41 // declare Thread that ensures automatic Light turn off 42 Thread thread = new Thread( 43 new Runnable() { 44 45 public void run() 46 { 47 // turn off Light if on for more than 3 seconds 48 try { 49 Thread.sleep( AUTOMATIC_TURNOFF_DELAY ); turnOffLight( lightLocation ); 51 } 52 53 // handle exception if interrupted 54 catch ( InterruptedException exception ) { 55 exception.printStackTrace(); 56 } 57 } 58 } // end anonymous inner class 59 ); Fig. H.10 Class Lightrepresents a Lighton the Floorin the model (part 2 of 3).
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.