/**
  *　移動を続けるエビを描画するアプレット
  */
  
  import java.awt.*;
  import java.awt.event.*;
  import java.applet.Applet;
  
    public class EbiMove extends Applet
           implements Runnable {

	     /* このアプレットの属性 */
	     Image img;		//　表示する画像（顔）
	     int x;		//　画像の表示位置の座標
	     Thread th;	        //　スレッド

	
	     /*メソッド１： void init（アプレットの初期化） */
	     public void init(){
		//　表示する画像・文字列を用意する
	      	 img = getImage(getDocumentBase(), "ebi.gif");	//　顔の画像を読み込む
			
	       	//　背景の色を定義する
	       	setBackground(Color.white);

	       	//　画像の表示位置のx座標の初期値を与える
	       	x = 0;
	     }
		

	     /* メソッド２：void start（アプレットの開始） */
	     public void start(){
	  	//　スレッドを生成して開始する
	       	if (th == null){
		 	th = new Thread(this);
		 	th.start();
	     	}
	       }


	     /* メソッド３：void stop（アプレットの停止） */	
	     public void stop(){
		//　スレッドを捨てる
		 if (th != null){
			th.stop();
			 th = null;
		}
	}
	
	
	 /* メソッド４：void run（スレッドの処理） */
	 public void run(){
		//　画像の位置をずらしながら繰り返し表示する
               		while (true) {
		 
		 	//　画像の位置をずらす
                 			x += 10;
  
			 //　アプレットの端にきたら画像の位置を調節する
                		 	if (x >= 500){	        //　右端にきた場合
                     			x = 0;		//　画像の位置をスタート地点に戻す
                  			 }
		 	//　画像を再描画する
			 repaint();
		 
			 //　スレッドの処理をいったん停止する
		 	try{
                  				Thread.sleep(100);
                 			}
                 			catch (InterruptedException e){
                 			}
              	 	}
	 }
	     
	     
	/* メソッド５：void paint（アプレットの描画） */
	public void paint(Graphics g){	 
		g.drawImage(img, x, 50, this);
	}
}
