import java.applet.Applet;
import java.awt.*;

public class Othello01 extends Applet implements Runnable
{
	static final int BOXWID = 64;
	static final int NONE = 0;
	static final int BLACK = 1;
	static final int WHITE = 2;
	static final int OUT = 3;
	MediaTracker mt = new MediaTracker(this);
	int[][] box = new int[10][10];
	Image[] black = new Image[9];
	Image[] white = new Image[9];
	Image offImage;
	Graphics offScreen;
	Thread thread;

	public void init() {
		Dimension d = size();
		offImage = createImage(d.width, d.height);
		offScreen = offImage.getGraphics();
		box[4][4] = BLACK;
		box[4][5] = WHITE;
		box[5][4] = WHITE;
		box[5][5] = BLACK;
		for (int n = 1; n <= 8; n++) {
			black[n] = getImage(getCodeBase(), "../../image/25_0"+n+".GIF");
			mt.addImage(black[n], 0);
			white[n] = getImage(getCodeBase(), "../../image/26_0"+n+".GIF");
			mt.addImage(white[n], 0);
		}
		try {
			mt.waitForID(0);
		} catch (InterruptedException e) {
		}
	}

	public void paint(Graphics g) {
		g.drawImage(offImage, 0, 0, null);
	}

	public void update(Graphics g) {
		paint(g);
	}

	public void start() {
		if (thread == null) {
			thread = new Thread(this);
			thread.start();
		}
	}

	public void stop() {
		if (thread != null) {
			thread.stop();
		}
		thread = null;
	}

	public void run() {
		int count = 1;
		Dimension d = size();
		while (true) {
			offScreen.setColor(Color.black);
			offScreen.fillRect(0, 0, d.width, d.height);
			for (int x = 1; x <=8; x++) {
				for (int y = 1; y <= 8; y++) {
					if (box[x][y] == BLACK) {
						offScreen.drawImage(black[count], (x-1)*BOXWID, (y-1)*BOXWID, null);
					} else if (box[x][y] == WHITE) {
						offScreen.drawImage(white[count], (x-1)*BOXWID, (y-1)*BOXWID, null);
					}
				}
			}
			if (++count > 8) count = 1;
			repaint();
			try {
				thread.sleep(100);
			} catch (InterruptedException e) {
			}
		}
	}
}

