⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 complete10_5.java

📁 程序练习中包括书中实例程序代码和练习中要用到的代码,是压缩文件
💻 JAVA
字号:
package questions.c10;

import java.util.Observable;
import java.util.Observer;
public class Complete10_5 {
   public static void main( String[] args ) {
      Motorist m = new Motorist();
      StopLight sl = new StopLight();
      sl.addObserver( m );
      sl.setLightColor( StopLight.RED );
      sl.setLightColor( StopLight.GREEN );
      sl.setLightColor( StopLight.YELLOW );
   }
   static private class StopLight extends Observable {
      public static final int RED = 0;
      public static final int YELLOW = 1;
      public static final int GREEN = 2;
      private int lightColor = RED;
      public int getLightColor() {
         return lightColor;
      }
      public void setLightColor( int color ) {
         switch ( color ) {
            case RED:
            case YELLOW:
            case GREEN:
               lightColor = color;
               setChanged();
               notifyObservers();
               break;
            default:
               // invalid, do nothing
         }
      }
   }
   // put your class Motorist here
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -