import java.applet.Applet;
import java.awt.*;

public class Test203 extends Applet implements Runnable {
	Color newColor;
	Thread test = null;

	public void init() {
		// 初期化
	}

	public void start() {
		if (test == null) {
			// スレッドを実行
			test = new Thread(this);
			test.start();
		}
	}

	public void stop() {
		if (test != null) {
			// スレッドを止める
			test.stop();
			test = null;
		}
	}

	public void run() {
		newColor = Color.blue;
		for(int i=0; i<6; i++) {
			// blueを５回明るくする
			newColor = bright(newColor);
		}

		while(true) {
			repaint();
			// repaintはupdateを呼び、updateはpaintを呼ぶ

			try {
				// スレッドの一時停止時間
				Thread.sleep(500);
			} catch (InterruptedException e){ }
			newColor = dark(newColor);	// １段暗い色を作る
		}
	}

	public void paint(Graphics g) {
		g.setColor(newColor);		// 色のセット
		g.fillRect(0, 0, 200, 200);	// 画面を塗る
	}

	// 明るい色を作る（コアＡＰＩ brighter()ソースの修正）
	public Color bright(Color c) {
		double b=15;
		return new Color(Math.min((int)(c.getRed()+b), 255), 
				 Math.min((int)(c.getGreen()+b), 255),
				 Math.min((int)(c.getBlue()+b), 255));
	}

	// 暗い色を作る（コアＡＰＩ darker()ソースからの修正）
	public Color dark(Color c) {
		double b=15;
		return new Color(Math.max((int)(c.getRed()-b), 0), 
				 Math.max((int)(c.getGreen()-b), 0),
				 Math.max((int)(c.getBlue()-b), 0));
	}



}
