public class LampController {
private Lamp currentLamp;
public LampController()
{
currentLamp=Lamp.S2N;//当前灯
currentLamp.light();//
ScheduledExecutorService scheduleds=Executors.newScheduledThreadPool(1);//定时器
scheduleds.scheduleAtFixedRate(new Runnable(){
public void run(){
currentLamp=currentLamp.blockOut();
}},
10,
100,
TimeUnit.SECONDS);
}
}//end
要运行这个程序就得有主函数:
//主函数
public class Main {
public static void main(String[] args) {
String[] roads=new String[]{"S2N","S2W","E2W","E2S","N2S","N2E","W2E","W2N","S2E","E2N","N2W","W2S"};
for(String road :roads)
{
new Road(road);//创建12个路的对象
}
new LampController();//定时器对象
}
}end 作者: 许庭洲 时间: 2013-9-2 20:46
值得学习ing!