home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 October / PCO1097.ISO / FilesBBS / WIN95 / CAFFEINE.ARJ / ANIMAX.CLA (.txt) next >
Encoding:
Java Class File  |  1996-05-18  |  3.6 KB  |  118 lines

  1. import java.applet.Applet;
  2. import java.awt.Color;
  3. import java.awt.Component;
  4. import java.awt.Event;
  5. import java.awt.Graphics;
  6. import java.awt.Image;
  7. import java.awt.MediaTracker;
  8. import java.net.URL;
  9.  
  10. public class animax extends Applet implements Runnable {
  11.    int wCount;
  12.    int currentImage;
  13.    int wWidth;
  14.    // $FF: renamed from: ms int
  15.    int field_0;
  16.    int wHeight;
  17.    int wFrames;
  18.    Image master;
  19.    Thread tDelay;
  20.    String sLink;
  21.    String sTarget;
  22.  
  23.    public void init() {
  24.       this.sLink = ((Applet)this).getParameter("link");
  25.       this.sTarget = ((Applet)this).getParameter("target");
  26.       Color clr = new Color(Integer.parseInt(((Applet)this).getParameter("red")), Integer.parseInt(((Applet)this).getParameter("green")), Integer.parseInt(((Applet)this).getParameter("blue")));
  27.       ((Component)this).setBackground(clr);
  28.       this.currentImage = 0;
  29.       this.wFrames = Integer.parseInt(((Applet)this).getParameter("frames"));
  30.       if (this.wFrames == 0) {
  31.          this.wFrames = 1;
  32.       }
  33.  
  34.       int fps = Integer.parseInt(((Applet)this).getParameter("fps"));
  35.       if (fps == 0) {
  36.          fps = 4;
  37.       }
  38.  
  39.       this.field_0 = 1000 / fps;
  40.    }
  41.  
  42.    public Image GetGIF(Applet caller, String sGifName) throws Exception {
  43.       MediaTracker mt = new MediaTracker(caller);
  44.       Image temp = caller.getImage(caller.getDocumentBase(), sGifName);
  45.       mt.addImage(temp, 0);
  46.       caller.showStatus("Loading " + sGifName);
  47.  
  48.       try {
  49.          mt.waitForID(0);
  50.       } catch (InterruptedException var5) {
  51.       }
  52.  
  53.       if (mt.isErrorID(0)) {
  54.          caller.showStatus("Error loading " + sGifName);
  55.          throw new Exception("Unable to load image " + sGifName);
  56.       } else {
  57.          return temp;
  58.       }
  59.    }
  60.  
  61.    public void start() {
  62.       if (this.tDelay == null) {
  63.          this.tDelay = new Thread(this);
  64.          this.tDelay.start();
  65.       }
  66.  
  67.    }
  68.  
  69.    public void stop() {
  70.       this.tDelay = null;
  71.    }
  72.  
  73.    public void run() {
  74.       for(; this.tDelay != null; ((Component)this).repaint()) {
  75.          try {
  76.             Thread.sleep((long)this.field_0);
  77.          } catch (InterruptedException var1) {
  78.          }
  79.  
  80.          ++this.currentImage;
  81.          if (this.currentImage == 14) {
  82.             this.currentImage = 0;
  83.          }
  84.       }
  85.  
  86.       this.tDelay = null;
  87.    }
  88.  
  89.    public void update(Graphics g) {
  90.       this.paint(g);
  91.    }
  92.  
  93.    public boolean mouseDown(Event evt, int x, int y) {
  94.       try {
  95.          ((Applet)this).getAppletContext().showDocument(new URL(((Applet)this).getDocumentBase(), this.sLink), this.sTarget);
  96.          return true;
  97.       } catch (Exception var4) {
  98.          return false;
  99.       }
  100.    }
  101.  
  102.    public void paint(Graphics g) {
  103.       if (this.master == null) {
  104.          g.clearRect(0, 0, 100, 100);
  105.  
  106.          try {
  107.             this.master = this.GetGIF(this, ((Applet)this).getParameter("image"));
  108.          } catch (Exception var2) {
  109.          }
  110.  
  111.          this.wHeight = this.master.getHeight(this) / this.wFrames;
  112.          this.wWidth = this.master.getWidth(this);
  113.       } else {
  114.          g.drawImage(this.master, 0, -this.wHeight * this.currentImage, this);
  115.       }
  116.    }
  117. }
  118.