
Write an applet to display scrolling image in an applet window using thread.

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<applet code=imgscrl height=300 width=300></applet>*/
public class imgscrl extends Applet implements Runnable
{
Thread t1=new Thread(this);
Image img;
int maxx=20,maxy=20;
public void init()
{
img=getImage(getDocumentBase(),"Cover.jpg");
t1.start();
}
public void run()
{
try
{
for(;;)
{
maxx+=20;
if(maxx==1000)
maxx=20;
Thread.sleep(500);
repaint();
}
}
catch(Exception e)
{
}
}
public void paint(Graphics g)
{
g.drawImage(img,maxx,maxy,this);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.