import java.awt.*;
import java.applet.*;
public class gv05 extends Applet implements Runnable
{


//animation with images
//fred42.gif is second moving image
//gv00.gif  about 200 wide x 200 tall
//bkg60.jpg 760x520 or size of applet
//<applet code="gv(number).class" height=520 width=760>
//moving image name
//<param name="myImage" value="your_name.gif">
//<param name="vMove" value="10">
//<param name="hMove" value="15"></applet>
//you can leave param blank and use the default
//gv00.gif 
//background
//bkg60.jpg 760 wide 520 tall



//declare parameter names... String and int required for numbers
String myGifString; 

String vMoveText;
int vMoveNum = 10;

String hMoveText;
int hMoveNum = 15;

int x=0;
int y=0;

int xx=400;
int yy=0;

int joe=1;
int joeq=1;

int joe2=1;
int joeq2=-1;

 private volatile Thread runner;

        private Image Buffer;
        private Graphics gBuffer;
        Image background, snail,snail2;
  
      Dimension appletSize;  

        //Init is called first, do any initialization here
        public void init()
        {
//create graphics buffer, the size of the applet
   appletSize = this.getSize();     
   Buffer = this.createImage(appletSize.width, appletSize.height);
gBuffer=Buffer.getGraphics();
background=getImage(getCodeBase(),"bkg60.jpg");

//get gif name parameters from webpage
myGifString = getParameter("myImage");
if(myGifString == null){myGifString="gv00.gif";}
snail=getImage(getCodeBase(),myGifString);

//another moving image
  snail2=getImage(getCodeBase(),"fred42.gif");    

//get parameters for integer 
//first read String value
//then check for null
//then convert to an integer number
vMoveText=getParameter("vMove");
if(vMoveText == null){vMoveText="10";}
vMoveNum = Integer.parseInt(vMoveText);

hMoveText=getParameter("hMove");
if(hMoveText == null){hMoveText="15";}
hMoveNum = Integer.parseInt(hMoveText);

        }



   



       public void start()
       {
              if (runner == null)
               {
                          runner = new Thread (this);
                         runner.start();
               }
       }




    public void stop() {
        runner = null;
    }

 public void run() {
        Thread thisThread = Thread.currentThread();
        while (runner == thisThread) {
            try {
                thisThread.sleep(35);
            } catch (InterruptedException e){}
           



                        gBuffer.drawImage(background,0,0,this);

  //move the picture
joe=joe+joeq;
if(joe>vMoveNum+7){joeq=-1;}
if(joe<-(vMoveNum+8)){joeq=1;}

joe2=joe2+joeq2;
if(joe2>hMoveNum+9){joeq2=-1;}
if(joe2<-(hMoveNum+10)){joeq2=1;}

//location of first moving image
x=x+3+joe2;
y=y+2+joe;
//location of second moving image fred42.gif
xx=xx-2-joe;
yy=yy+3+joe2;

                        //if it moves past the right border,
                        //let it reappear on the left border
  if(x>appletSize.width){x=-200;}
  if(y>appletSize.height){y=-200;}
  if(x<-200){x=appletSize.width;}
  if(y<-200){y=appletSize.height;}

  if(xx>appletSize.width){xx=-200;}
  if(yy>appletSize.height){yy=-200;}
  if(xx<-200){xx=appletSize.width;}
  if(yy<-200){yy=appletSize.height;}

                        gBuffer.drawImage(snail,x,y,this);
 gBuffer.drawImage(snail2,xx,yy,this);



 
            repaint();
        }
    }


   //is needed to avoid erasing the background by Java
   public void update(Graphics g)
   {
                paint(g);
   }

   public void paint(Graphics g)
   {
                g.drawImage (Buffer,0,0, this);
   }
}