ColorfulFrame.java



import java.awt.Frame;
import java.awt.Color;

/** 様々に色が変化する ColorfulFrameクラス */

public class ColorfulFrame extends Frame implements Runnable {

  /** スレッド */

       public Thread thread;

  /** 色のデータの表 */

       protected Color colors[];

  /** カウンタ */

       private int count=0;

  /** コンストラクタ */

       ColorfulFrame( int width, int height ) {

              super();

              colors = new Color[7];
              colors[0] = Color.red;    colors[1] = Color.orange;
              colors[2] = Color.yellow; colors[3] = Color.green;
              colors[4] = Color.cyan;   colors[5] = Color.blue;
              colors[6] = Color.magenta;

              thread = new Thread( this );  //スレッドの生成

              setSize( width, height );     // JDK1.0 では resize()
              setBackground( colors[0] );
              show();
       }

  /** スレッドによって実行される仕事 */

       public void run() {

              while( thread.isAlive() ) {

                    try {
                          Thread.sleep(1000); // 一秒間停止
                    } catch(Exception e) {/* 本当は処理が必要 */}
                    setBackground( colors[count] );
                    count++;
                    if( count > 6 ) count=0;
              }
       }
}