Search Your Topic

config
Thursday, 25 May 2017 06:16

Animation in Applet

Written by
Rate this item
(0 votes)
Applet is mostly used in games and animation. For this purpose image is required to be moved.

Example of animation in applet:

 
  1. import java.awt.*;  
  2. import java.applet.*;  
  3. public class AnimationExample extends Applet {  
  4.   
  5.   Image picture;  
  6.   
  7.   public void init() {  
  8.     picture =getImage(getDocumentBase(),"bike_1.gif");  
  9.   }  
  10.     
  11.   public void paint(Graphics g) {  
  12.     for(int i=0;i<500;i++){  
  13.       g.drawImage(picture, i,30this);  
  14.   
  15.       try{Thread.sleep(100);}catch(Exception e){}  
  16.     }  
  17.   }  
  18. }  
In the above example, drawImage() method of Graphics class is used to display the image. The 4th argument of drawImage() method of is ImageObserver object. The Component class implements ImageObserver interface. So current class object would also be treated as ImageObserver because Applet class indirectly extends the Component class.

myapplet.html

 

 
  1. <html>  
  2. <body>  
  3. <applet code="DisplayImage.class" width="300" height="300">  
  4. </applet>  
  5. </body>  
  6. </html>  
Read 123 times
Anish Sir

"I am delighted once again to pen the welcome note to the Tosh!Yas Technologies ."

 Call +91 74 88 34 7779  | Email : anishsingh@live.com

toshiyas.in

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.

Facebook