home *** CD-ROM | disk | FTP | other *** search
- import java.applet.Applet;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.Event;
- import java.awt.Graphics;
- import java.awt.Image;
-
- public class ImageSequence extends Applet implements Runnable {
- int frameNumber = -1;
- int delay;
- Thread animatorThread;
- boolean frozen = false;
- Dimension offDimension;
- Image offImage;
- Graphics offGraphics;
- Image[] images;
-
- public void init() {
- int var2 = 10;
- String var1 = ((Applet)this).getParameter("fps");
-
- try {
- if (var1 != null) {
- var2 = Integer.parseInt(var1);
- }
- } catch (Exception var4) {
- }
-
- this.delay = var2 > 0 ? 1000 / var2 : 100;
- this.images = new Image[10];
-
- for(int var3 = 1; var3 <= 10; ++var3) {
- this.images[var3 - 1] = ((Applet)this).getImage(((Applet)this).getCodeBase(), "../../../images/duke/T" + var3 + ".gif");
- }
-
- }
-
- public void start() {
- if (!this.frozen) {
- if (this.animatorThread == null) {
- this.animatorThread = new Thread(this);
- }
-
- this.animatorThread.start();
- }
-
- }
-
- public void stop() {
- this.animatorThread = null;
- this.offGraphics = null;
- this.offImage = null;
- }
-
- public boolean mouseDown(Event var1, int var2, int var3) {
- if (this.frozen) {
- this.frozen = false;
- this.start();
- } else {
- this.frozen = true;
- this.animatorThread = null;
- }
-
- return true;
- }
-
- 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) {
- this.update(var1);
- }
-
- public void update(Graphics var1) {
- Dimension var2 = ((Component)this).size();
- if (this.offGraphics == null || var2.width != this.offDimension.width || var2.height != this.offDimension.height) {
- this.offDimension = var2;
- this.offImage = ((Component)this).createImage(var2.width, var2.height);
- this.offGraphics = this.offImage.getGraphics();
- }
-
- this.offGraphics.setColor(((Component)this).getBackground());
- this.offGraphics.fillRect(0, 0, var2.width, var2.height);
- this.offGraphics.setColor(Color.black);
- this.offGraphics.drawImage(this.images[this.frameNumber % 10], 0, 0, this);
- var1.drawImage(this.offImage, 0, 0, this);
- }
- }
-