/*  * DblScrlAnimator.java 0.95 1997.8.31 (Double Scroll Animator) * * written by SAkira (mailto:sakira.09@g4.mnx.ne.jp) *  * このアプレットは Sun Microsystems の Animator.java と * ImageLoopItem.java, * 翔泳社の「一歩先行くインターネット　Java入門」 * (有我成城　他５名の共著, ISBN4-88135-351-9) 中の * サンプルを参考に作らせて頂きました。 * * このアプレットを使用するにあたって私(さきら)に許可を得る * 必要はありません。 */import java.applet.Applet;import java.awt.*;/** * このアプレットは幅 x dot, 高さ y dotの画像を縦に n個繋げた * 単一の画像(幅 x dot, 高さ y*n dot)を読み込んで、 * loopアニメーションするものです。 * 二つの画像を指定する事によって、二つの動画を同期させながら * アニメーションさせる事もできます。これは裸眼立体視に * 使えます。詳しくは<A HREF="http://sundent.mine.nu/~sakira/"> * さきらのホームページ</A>にて解説する予定です。 * (1997.8.31現在準備中) *  * @author SAkira * @version 0.95, 1997.08.31 */public class DblScrlAnimator extends Applet 		implements Runnable {	/** 現在表示中のコマ */	int current;		/** 用意する画像（左・右） */	Image imageL, imageR;		/** 各々アプレットに渡すパラメータに対応 */	int last, iwidth, iheight, wait, firstwait, lastwait;		/** 画像をアニメーションさせる為のスレッド */	Thread thread;		/** off screen image */	Image offScrImage;		/** off screen image用の Graphics */	Graphics offScrGC;	public void init() {		current = 0;		last = 10;		iwidth = 600; iheight = 300;		wait = 500;		imageL = null; imageR = null;		String s = null;				// 画像の読み込み		s = getParameter("imagefileL");		if (s != null)			imageL = getImage(getDocumentBase(), s);		s = getParameter("imagefileR");		if (s != null)			imageR = getImage(getDocumentBase(), s);				// コマ数		s = getParameter("last");		if (s != null) last = Integer.parseInt(s);				// 一コマの大きさ		s = getParameter("iheight");		if (s != null) iheight = Integer.parseInt(s);		s = getParameter("iwidth");		if (s != null) iwidth = Integer.parseInt(s);				// コマの間の待ち時間		s = getParameter("wait");		if (s != null) wait = Integer.parseInt(s);		s = getParameter("firstwait");		if (s != null) firstwait = Integer.parseInt(s);			else firstwait = wait;		s = getParameter("lastwait");		if (s != null) lastwait = Integer.parseInt(s);			else lastwait = wait;				// オフスクリーンの準備		if (imageR != null) {			// 画像は二つ			offScrImage = createImage(iwidth * 2, iheight);		} else {			// 画像は一つ			offScrImage = createImage(iwidth, iheight);		}		offScrGC = offScrImage.getGraphics();	}		public void start() {		if (thread == null) {			thread = new Thread(this);			thread.start();		}	}		public void stop() {		if (thread != null) {			thread.stop();			thread = null;		}	}		public void paint(Graphics g) {		update(g);	}		public void update(Graphics g) {		// current のコマをオフスクリーンに書き込む		offScrGC.drawImage(imageL, 0, -current * iheight, this);		// もし右の画像もあればオフスクリーンに書き込む		if (imageR != null)			offScrGC.drawImage(imageR, iwidth, -current * iheight, this);		// 表示する		g.drawImage(offScrImage, 0, 0, this);/*		g.translate(0, -current * iheight);		g.drawImage(imageL, 0, 0, this);				if (imageR != null) {			g.drawImage(imageR, iwidth, 0, this);		}*/	}		// 決められた時間がきたらcurrentを一つ増やす	public void run() {		Thread.currentThread().setPriority(Thread.MIN_PRIORITY);		while(true) {			try {				if (current == 0) {					Thread.sleep(firstwait);				} else if (current == last - 1) {					Thread.sleep(lastwait);				} else {					Thread.sleep(wait);				}			} catch (InterruptedException e) {				break;			}			current++;			if (current >= last) current = 0;			repaint();		}	}		// これは要らない消してもいい	public boolean mouseDown(Event e, int x, int y) {		current++;		if (current >= last) current = 0;		repaint();		return true;	}}
