controller.java
来自「演示win32的socket 通讯 八皇后的改进算法 并发Concurren」· Java 代码 · 共 55 行
JAVA
55 行
package concurrency.cruise;
class Controller {
final static int INACTIVE = 0; // cruise controller states
final static int ACTIVE = 1;
final static int CRUISING = 2;
final static int STANDBY = 3;
private int controlState = INACTIVE; //initial state
private SpeedControl sc;
private boolean isfixed;
Controller(CarSpeed cs, CruiseDisplay disp, boolean b)
{sc=new SpeedControl(cs,disp); isfixed=b;}
synchronized void brake(){
if (controlState==CRUISING )
{sc.disableControl(); controlState=STANDBY; }
}
synchronized void accelerator(){
if (controlState==CRUISING )
{sc.disableControl(); controlState=STANDBY; }
}
synchronized void engineOff(){
if(controlState!=INACTIVE) {
if (isfixed && controlState==CRUISING) sc.disableControl(); //bugfix
controlState=INACTIVE;
}
}
synchronized void engineOn(){
if(controlState==INACTIVE)
{sc.clearSpeed(); controlState=ACTIVE;}
}
synchronized void on(){
if(controlState!=INACTIVE){
sc.recordSpeed(); sc.enableControl();
controlState=CRUISING;
}
}
synchronized void off(){
if(controlState==CRUISING )
{sc.disableControl(); controlState=STANDBY;}
}
synchronized void resume(){
if(controlState==STANDBY)
{sc.enableControl(); controlState=CRUISING;}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?