Java TrafficStateMachine Example

说明

java trafficstatemachine示例是从最受好评的开源项目中提取的实现代码,你可以参考下面示例的使用方式。

编程语言: Java

类/类型: TrafficStateMachine

示例#1
文件: TrafficSignalGreenState.java项目: Nerpson/TrafficSignal-Java-Design-Pattern-Behavioral

 public TrafficSignalGreenState(TrafficStateMachine context) {
   context.setColor(Color.GREEN);
 }

示例#2
文件: TrafficSignalGreenState.java项目: Nerpson/TrafficSignal-Java-Design-Pattern-Behavioral

 @Override
 public void notifyTime(int passedTime, TrafficStateMachine context) {
   if (passedTime == TIMEOUT) {
     context.setState(new TrafficSignalOrangeState(context));
   }
 }

示例#3
文件: TrafficSignalGreenState.java项目: Nerpson/TrafficSignal-Java-Design-Pattern-Behavioral

 @Override
 public void buttonPressed(TrafficStateMachine context) {
   if ((TIMEOUT - context.getTime()) > 2) {
     context.setTime(TIMEOUT - 2);
   }
 }

示例#4
文件: TrafficSignalRedState.java项目: Nerpson/TrafficSignal-Java-Design-Pattern-Behavioral

 public TrafficSignalRedState(TrafficStateMachine context) {
   context.setColor(Color.RED);
 }

展开阅读全文