我给JAVA的实现吧:
=============================
package zrweng.JavaThread;
/**
*线程定时器
*/
import java.awt.*;
public class TimerThread extends Thread{
Component comp;
int timediff;
volatile boolean shouldRun;
public TimerThread(Component comp,int timediff){
this.comp=comp;
this.timediff=timediff;
shouldRun=true;
}
public void run(){
while(shouldRun){
try{
comp.repaint();
sleep(timediff);
}
catch(Exception e){
}
}
}
========================================
package zrweng.JavaThread;
/**
Applet动画主程序,显示十副动画
*/
import java.applet.*;
import java.awt.*;
public class Animate extends Applet{
int count;
int lastcount;
Image[] pictures;
TimerThread timer=null;
public void init(){
lastcount=10;
count=0;
pictures=new Image[10];
MediaTracker tracker=new MediaTracker(this);
for(int a=0;a<lastcount;a++){
pictures[a]=getImage(this.getCodeBase(),new Integer(a).toString()+".jpg");
tracker.addImage(pictures[a],0);
}
tracker.checkAll(true);
}
public void start(){
timer=new TimerThread(this, 1000);
timer.start();
}
public void stop(){
timer.shouldRun=false;
try{
timer.join();
}
catch(InterruptedException e){
}
timer=null;
}
public void paint(Graphics g){
g.drawImage(pictures[count++],0,0,null);
if(count==lastcount)
count=0;
}
public void printThreads(){
Thread ta[]=new Thread[Thread.activeCount()];
int n=Thread.enumerate(ta);
for(int i=0;i<n;i++)
System.out.println("Thread "+i+" is "+ta.getName());
}
}