This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Applets and the fly likes Applet Image Animation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Applet Image Animation" Watch "Applet Image Animation" New topic
Author

Applet Image Animation

saif rehman
Greenhorn

Joined: Sep 04, 2011
Posts: 4

Hi !
Please check this out .what is the problem with the following code ? I have tried so much but i don't get it...


import java.awt.*;
import java.applet.*;


public class Animate extends Applet implements Runnable{
int count;
Thread timer;
Image pictures[]=new Image[1];

public void init(){
count=0;
pictures[0]=getImage(getCodeBase(),"green.jpeg");
}

public void start(){
if(timer==null){
timer=new Thread(this);
timer.start();
}
}
public void paint(Graphics g){
g.drawImage(pictures[count],0,0,this);
}

public void run(){
while(isActive()){
try{
repaint();
Thread.sleep(1000);
}catch(Exception e){
e.printStackTrace();
}
}
timer=null;
}
}
This is the code for Animation of Images in the Applet. But it doesn't even draw a single image.
when I execute the Applet in the browser it shows nothing..
Enrico Rosina
Greenhorn

Joined: Nov 06, 2010
Posts: 14
Hello,

Your image was not found. Could you try something like this to load the image:

Is it better?
 
 
subject: Applet Image Animation
 
Similar Threads
Why isnt my thread rerstarted?
well did as below but BUTTONS NOT Appear only the image plays continuesly, well
haveing trouble with applet animation plz help
Need help with my game.
Images don't appear in Swing code