Animation in applet

Animation in applet

One of the uses of applets is in performing animation and devoloping games. Animation represents moving object from one place to another. To animate an object, we should first load it into image class object,
Image img = getImage(getDocumentBase(), ”image.jpg”);

Example

test.java

import java.awt.*;
import java.applet.*;
public class test extends Applet
{
public void paint(Graphics g)
{
Image img = getImage(getDocumentBase(),”java1.jpg”);
for(int i=0;i<500;i++)
{
g.drawImage(img, i,30, this);
try{
Thread.sleep(20);
}
catch(Exception e){}
}
}
}

New.html

<html>
<body>
<applet code=”test.class” width=”600″ height=”800″>
</applet>
</body>
</html>

Leave a Reply

Your email address will not be published. Required fields are marked *