📄 traffic_light.java
字号:
/*
* Created on 2006-11-9
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package traffic;
/**
* @author alvin
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class Traffic_light extends Thread {
private Master master;
Traffic_light(Master parent) {
this.master = parent;
}
public void run() {
while (true) {
//1 turn left
if (master.getLight() == 1) {
master.setLight(2);
System.out.println("1 turn left can go straight");
try {
this.sleep(3000);
} catch (InterruptedException e) {
System.err.println("Interrupted");
}
}
//1 straight
else if (master.getLight() == 2) {
master.setLight(3);
System.out.println("1 straight 2 can turn left");
try {
this.sleep(3000);
} catch (InterruptedException e) {
System.err.println("Interrupted");
}
}
//2 turn left
else if (master.getLight() == 3) {
master.setLight(4);
System.out.println("2 turn left 2 can go straight");
try {
this.sleep(3000);
} catch (InterruptedException e) {
System.err.println("Interrupted");
}
}
//2 straight
else if (master.getLight() == 4) {
master.setLight(1);
System.out.println("2 straight 1 can turn left");
try {
this.sleep(3000);
} catch (InterruptedException e) {
System.err.println("Interrupted");
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -