/*
 * ParaPara.java
 * copyright (c) since 2004 "Kimmy" all right reserved.
 */

/*
<applet code="ParaPara.class" width=192 height=192>
</applet>
*/

import java.applet.*;
import java.awt.*;
import java.awt.image.*;

public class ParaPara extends Applet implements Runnable{

    public int t; 
    public Dimension d;
    public Image im[], bi;
    public Graphics bg;

    public Thread show;
    public boolean loaded;
 
    public void init(){
	t = 0;
	String temp[] = 
	    {"001", "002", "003", "003", "005", "006", "007", "007", 
	     "001", "002", "003", "003", "013", "013", "015", "015", 
	     "001", "002", "003", "003", "005", "006", "007", "007",  
	     "001", "002", "003", "003", "029", "029", "031", "032", 
	     "101", "102", "103", "102", "105", "106", "107", "106", 
	     "105", "106", "107", "106", "113", "113", "115", "115", 
	     "117", "117", "115", "115", "121", "122", "123", "122", 
	     "105", "106", "107", "106", "105", "106", "107", "106",
	     "113", "113", "115", "115", "117", "117", "115", "115", 
	     "201", "201", "203", "204", "201", "201", "207", "208", 
	     "203", "204", "207", "208", "213", "213", "215", "215", 
	     "201", "201", "203", "204", "201", "201", "207", "208", 
	     "203", "204", "207", "208", "229", "230", "231", "231", 
	     "301", "302", "303", "304", "305", "302", "304", "304", 
	     "309", "309", "311", "311", "313", "313", "315", "315", 
	     "317", "318", "319", "320", "321", "322", "323", "324", 
	     "325", "326", "327", "327", "329", "330", "331", "331",  
	     "301", "302", "303", "304", "305", "302", "304", "304", 
	     "309", "309", "311", "311", "313", "313", "315", "315", 
	     "317", "318", "319", "320", "321", "322", "323", "324", 
	     "325", "326", "327", "327", "329", "330", "331", "331"};
	im = new Image[temp.length];
	for(int i=0; i<temp.length; i++){
	    im[i] = getImage(getDocumentBase(), "./fig/" + temp[i] + ".gif");
	}
	loaded = false;

	this.setBackground(Color.white); 
        d = this.getSize();
        bi = createImage(d.width, d.height);
	bg = bi.getGraphics();
    }

    public void start(){
	show = new Thread(this);
	show.start();
    }

    public void stop(){
	show = null;
    }

    public void run(){
	while(true){
	    loaded = false;
	    show.setPriority(show.MIN_PRIORITY);
	    repaint();
	    try{
		show.sleep(500);
	    }catch(InterruptedException e){
		
	    }
	    t++;
	    if(t==im.length){
		t = 0;
	    }
	}
    }

    public void paint(Graphics g){
	loaded = g.drawImage(bi, 0, 0, this);
    }

    public void update(Graphics g){
	loaded = bg.drawImage(im[t], 0, 0, this);
	g.drawImage(bi, 0, 0, null);
    }

}
