S O U R C E C O D E
/ 1999 / 11
/ java
/ 3.lst
// Base class for animated applets
// uses the Virtual Graphics applet as a base class
public class AniApplet extends Vapplet implements Runnable
{
Thread thread;
public int timerate=100; // milliseconds per frame
// kick off animation thread
public void start()
{
if (thread==null)
{
thread=new Thread(this);
thread.start();
}
}
// Stop thread
public void stop()
{
thread=null;
}
// Here is the main animation thread
public void run()
{
long time=System.currentTimeMillis();
int i;
while (thread!=null)
{
try
{
time+=timerate; // wait for next frame
Thread.sleep(Math.max(0,time-System.currentTimeMillis()));
}
catch (InterruptedException e) { }
animate();
}
}
public void animate() // derived classes will override
{
}
}
|
home
|
current issue
|
archives
|
source code
|
demo express
|
events
|
search
|
editorial calendar
|
advertising
|
customer service
|
author guidelines
|
jobs
|
about
Entire contents copyright 1996-2000 CMP Media Inc.
Read our privacy policy.