programming challenge in java-2
check out this code
import java.applet.*;This is a program which move an image and stop at some distance.
import java.awt.*;
/*<APPLET CODE="k.class" HEIGHT=400 WIDTH=900></APPLET>*/
public class k extends Applet implements Runnable
{
Image img,im,p;
int x=0,y=0;
Thread t,t1;
public void init()
{
img=getImage(getDocumentBase(),"cc.gif");
}
public void start()
{
t=new Thread(this);
t.start();
}
public void run()
{
try
{
for(int i=0;i<=20;i++)
{
p=img;
repaint();
t.sleep(50);
x=x+20;
}
}
catch(InterruptedException e)
{
System.out.println("interrupted exception ");
}
}
public void paint(Graphics g)
{
g.drawImage(p,x,20,100,100,this);
}
}
You have to edit it in this way that after 1st image stop 2nd image start to move from same position and stop just before 1st one.
.