?? light.java
字號:
// Light.java// Light turns a light on or offpackage com.Anance.elevator.model;// Deitel packagesimport com.Anance.elevator.event.*;public class Light implements ElevatorMoveListener { // Light state (on/off) private boolean lightOn; // time before Light turns off automatically (3 seconds) public static final int AUTOMATIC_TURNOFF_DELAY = 3000; // LightListener listens for when Light should turn on/off private LightListener lightListener; // location where Light turned on or off private Location lightLocation; // set LightListener public void setLightListener( LightListener listener ) { lightListener = listener; } // turn on Light public void turnOnLight( Location location ) { if ( !lightOn ) { lightOn = true; // send LightEvent to LightListener lightListener.lightTurnedOn( new LightEvent( this, location ) ); lightLocation = location; // declare Thread that ensures automatic Light turn off Thread thread = new Thread( new Runnable() { public void run() { // turn off Light if on for more than 3 seconds try { Thread.sleep( AUTOMATIC_TURNOFF_DELAY ); turnOffLight( lightLocation ); } // handle exception if interrupted catch ( InterruptedException exception ) { exception.printStackTrace(); } } } // end anonymous inner class ); thread.start(); } } // end method turnOnLight // turn off Light public void turnOffLight( Location location ) { if ( lightOn ) { lightOn = false; // send LightEvent to LightListener lightListener.lightTurnedOff( new LightEvent( this, location ) ); } } // end method turnOffLight // return whether Light is on or off public boolean isLightOn() { return lightOn; } // invoked when Elevator has departed public void elevatorDeparted( ElevatorMoveEvent moveEvent ) { turnOffLight( moveEvent.getLocation() ); } // invoked when Elevator has arrived public void elevatorArrived( ElevatorMoveEvent moveEvent ) { turnOnLight( moveEvent.getLocation() ); }}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -