home *** CD-ROM | disk | FTP | other *** search
- import java.awt.Component;
- import java.awt.Event;
- import java.awt.Frame;
- import java.awt.Graphics;
- import java.awt.Window;
-
- public class AnimatorApplication extends Frame implements Runnable {
- int frameNumber = -1;
- int delay;
- Thread animatorThread;
- boolean frozen = false;
-
- AnimatorApplication(int var1, String var2) {
- super(var2);
- this.delay = var1 > 0 ? 1000 / var1 : 100;
- }
-
- public void startAnimation() {
- if (!this.frozen) {
- if (this.animatorThread == null) {
- this.animatorThread = new Thread(this);
- }
-
- this.animatorThread.start();
- }
-
- }
-
- public void stopAnimation() {
- this.animatorThread = null;
- }
-
- public boolean mouseDown(Event var1, int var2, int var3) {
- if (this.frozen) {
- this.frozen = false;
- this.startAnimation();
- } else {
- this.frozen = true;
- this.stopAnimation();
- }
-
- return true;
- }
-
- public boolean handleEvent(Event var1) {
- switch (var1.id) {
- case 201:
- System.exit(0);
- case 202:
- default:
- break;
- case 203:
- this.stopAnimation();
- break;
- case 204:
- this.startAnimation();
- }
-
- return super.handleEvent(var1);
- }
-
- public void run() {
- Thread.currentThread().setPriority(1);
- long var1 = System.currentTimeMillis();
-
- while(Thread.currentThread() == this.animatorThread) {
- ++this.frameNumber;
- ((Component)this).repaint();
-
- try {
- var1 += (long)this.delay;
- Thread.sleep(Math.max(0L, var1 - System.currentTimeMillis()));
- } catch (InterruptedException var3) {
- return;
- }
- }
-
- }
-
- public void paint(Graphics var1) {
- var1.drawString("Frame " + this.frameNumber, 5, 50);
- }
-
- public static void main(String[] var0) {
- Object var1 = null;
- int var2 = 10;
- if (var0.length > 0) {
- try {
- var2 = Integer.parseInt(var0[0]);
- } catch (Exception var3) {
- }
- }
-
- AnimatorApplication var4 = new AnimatorApplication(var2, "Animator");
- ((Component)var4).resize(200, 60);
- ((Window)var4).show();
- var4.startAnimation();
- }
- }
-