home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / VCafe / WDESAMPL.BIN / Animator.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-09-18  |  15.9 KB  |  764 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Dimension;
  6. import java.awt.Event;
  7. import java.awt.Graphics;
  8. import java.awt.Image;
  9. import java.awt.MediaTracker;
  10. import java.awt.Point;
  11. import java.awt.image.ImageObserver;
  12. import java.net.MalformedURLException;
  13. import java.net.URL;
  14. import java.util.Enumeration;
  15. import java.util.Hashtable;
  16. import java.util.Vector;
  17.  
  18. public class Animator extends Applet implements Runnable {
  19.    Vector images;
  20.    Hashtable imageNames = new Hashtable(10);
  21.    Hashtable durations;
  22.    Hashtable sounds;
  23.    Hashtable positions;
  24.    static final int STARTUP_ID = 0;
  25.    static final int BACKGROUND_ID = 1;
  26.    static final int ANIMATION_ID = 2;
  27.    URL startUpImageURL;
  28.    Image startUpImage;
  29.    URL backgroundImageURL;
  30.    Image backgroundImage;
  31.    Color backgroundColor;
  32.    URL soundtrackURL;
  33.    AudioClip soundtrack;
  34.    URL hrefURL;
  35.    String hrefTarget;
  36.    int appWidth;
  37.    int appHeight;
  38.    URL imageSource;
  39.    URL soundSource;
  40.    Thread engine;
  41.    int frameNum;
  42.    Integer frameNumKey;
  43.    int xPos;
  44.    int yPos;
  45.    public static final int defaultPause = 3900;
  46.    int globalPause = 3900;
  47.    boolean userPause = false;
  48.    boolean repeat;
  49.    Image offScrImage;
  50.    Graphics offScrGC;
  51.    MediaTracker tracker;
  52.    boolean loaded = false;
  53.    boolean error = false;
  54.    static final String imageLabel = "image";
  55.    static final String soundLabel = "sound";
  56.    static final boolean debug = false;
  57.    static final String sourceLocation = "http://java.sun.com/applets/applets/Animator/";
  58.    static final String userInstructions = "shift-click for errors, info";
  59.  
  60.    public String getAppletInfo() {
  61.       return "Animator v1.9 (06/18/96), by Herb Jellinek";
  62.    }
  63.  
  64.    public String[][] getParameterInfo() {
  65.       String[][] var1 = new String[][]{{"imagesource", "URL", "a directory"}, {"startup", "URL", "image displayed at start-up"}, {"backgroundcolor", "int", "color (24-bit RGB number) displayed as background"}, {"background", "URL", "image displayed as background"}, {"startimage", "int", "index of first image"}, {"endimage", "int", "index of last image"}, {"namepattern", "URL", "generates indexed names"}, {"images", "URLs", "list of image indices"}, {"href", "URL", "page to visit on mouse-click"}, {"target", "name", "frame to put that page in"}, {"pause", "int", "global pause, milliseconds"}, {"pauses", "ints", "individual pauses, milliseconds"}, {"repeat", "boolean", "repeat? true or false"}, {"positions", "coordinates", "path images will follow"}, {"soundsource", "URL", "audio directory"}, {"soundtrack", "URL", "background music"}, {"sounds", "URLs", "list of audio samples"}};
  66.       return var1;
  67.    }
  68.  
  69.    void showDescription() {
  70.       DescriptionFrame var1 = new DescriptionFrame();
  71.       var1.tell("\t\t" + this.getAppletInfo() + "\n");
  72.       var1.tell("Updates, documentation at http://java.sun.com/applets/applets/Animator/\n\n");
  73.       var1.tell("Document base: " + ((Applet)this).getDocumentBase() + "\n");
  74.       var1.tell("Code base: " + ((Applet)this).getCodeBase() + "\n\n");
  75.       Object[] var2 = this.tracker.getErrorsAny();
  76.       if (var2 != null) {
  77.          var1.tell("Applet image errors:\n");
  78.  
  79.          for(int var3 = 0; var3 < var2.length; ++var3) {
  80.             if (var2[var3] instanceof Image) {
  81.                URL var4 = (URL)this.imageNames.get((Image)var2[var3]);
  82.                if (var4 != null) {
  83.                   var1.tell(" " + var4 + " not loaded\n");
  84.                }
  85.             }
  86.          }
  87.  
  88.          var1.tell("\n");
  89.       }
  90.  
  91.       if (this.images == null || this.images.size() == 0) {
  92.          var1.tell("\n** No images loaded **\n\n");
  93.       }
  94.  
  95.       var1.tell("Applet parameters:\n");
  96.       var1.tell(" width = " + ((Applet)this).getParameter("WIDTH") + "\n");
  97.       var1.tell(" height = " + ((Applet)this).getParameter("HEIGHT") + "\n");
  98.       String[][] var6 = this.getParameterInfo();
  99.  
  100.       for(int var7 = 0; var7 < var6.length; ++var7) {
  101.          String var5 = var6[var7][0];
  102.          var1.tell(" " + var5 + " = " + ((Applet)this).getParameter(var5) + "\t [" + var6[var7][2] + "]\n");
  103.       }
  104.  
  105.       var1.show();
  106.    }
  107.  
  108.    void dbg(String var1) {
  109.    }
  110.  
  111.    public String getParam(String var1) {
  112.       String var2 = ((Applet)this).getParameter(var1);
  113.       this.dbg("getParameter(" + var1 + ") = " + var2);
  114.       return var2;
  115.    }
  116.  
  117.    final int setFrameNum(int var1) {
  118.       this.frameNumKey = new Integer(this.frameNum = var1);
  119.       return this.frameNum;
  120.    }
  121.  
  122.    Vector parseImages(String var1, String var2) throws MalformedURLException {
  123.       if (var2 == null) {
  124.          var2 = "T%N.gif";
  125.       }
  126.  
  127.       Vector var3 = new Vector(10);
  128.  
  129.       int var5;
  130.       for(int var4 = 0; var4 < var1.length(); var4 = var5 + 1) {
  131.          var5 = var1.indexOf(124, var4);
  132.          if (var5 == -1) {
  133.             var5 = var1.length();
  134.          }
  135.  
  136.          String var6 = var1.substring(var4, var5);
  137.          var3.addElement(new URL(this.imageSource, this.doSubst(var2, var6)));
  138.       }
  139.  
  140.       return var3;
  141.    }
  142.  
  143.    Image fetchImageAndWait(URL var1, int var2) throws InterruptedException {
  144.       Image var3 = ((Applet)this).getImage(var1);
  145.       this.tracker.addImage(var3, var2);
  146.       this.imageNames.put(var3, var1);
  147.       this.tracker.waitForID(var2);
  148.       return var3;
  149.    }
  150.  
  151.    boolean fetchImages(Vector var1) {
  152.       if (var1 == null) {
  153.          return true;
  154.       } else {
  155.          int var2 = var1.size();
  156.  
  157.          for(int var3 = 0; var3 < var2; ++var3) {
  158.             Object var4 = var1.elementAt(var3);
  159.             if (var4 instanceof URL) {
  160.                URL var5 = (URL)var4;
  161.                this.tellLoadingMsg(var5, "image");
  162.                Image var6 = ((Applet)this).getImage(var5);
  163.                this.tracker.addImage(var6, 2);
  164.                var1.setElementAt(var6, var3);
  165.                this.imageNames.put(var6, var5);
  166.             }
  167.          }
  168.  
  169.          try {
  170.             this.tracker.waitForID(2);
  171.          } catch (InterruptedException var7) {
  172.          }
  173.  
  174.          if (this.tracker.isErrorID(2)) {
  175.             return false;
  176.          } else {
  177.             return true;
  178.          }
  179.       }
  180.    }
  181.  
  182.    Hashtable parseSounds(String var1, Vector var2) throws MalformedURLException {
  183.       Hashtable var3 = new Hashtable();
  184.       int var4 = 0;
  185.       int var5 = var2.size();
  186.  
  187.       for(int var6 = 0; var6 < var1.length() && var4 < var5; ++var4) {
  188.          int var7 = var1.indexOf(124, var6);
  189.          if (var7 == -1) {
  190.             var7 = var1.length();
  191.          }
  192.  
  193.          String var8 = var1.substring(var6, var7);
  194.          if (var8.length() != 0) {
  195.             var3.put(new Integer(var4), new URL(this.soundSource, var8));
  196.          }
  197.  
  198.          var6 = var7 + 1;
  199.       }
  200.  
  201.       return var3;
  202.    }
  203.  
  204.    URL fetchSounds(Hashtable var1) {
  205.       Enumeration var2 = var1.keys();
  206.  
  207.       while(var2.hasMoreElements()) {
  208.          Integer var3 = (Integer)var2.nextElement();
  209.          Object var4 = var1.get(var3);
  210.          if (var4 instanceof URL) {
  211.             URL var5 = (URL)var4;
  212.             this.tellLoadingMsg(var5, "sound");
  213.  
  214.             try {
  215.                var1.put(var3, ((Applet)this).getAudioClip(var5));
  216.             } catch (Exception var6) {
  217.                return var5;
  218.             }
  219.          }
  220.       }
  221.  
  222.       return null;
  223.    }
  224.  
  225.    Hashtable parseDurations(String var1, Vector var2) {
  226.       Hashtable var3 = new Hashtable();
  227.       int var4 = 0;
  228.       int var5 = var2.size();
  229.  
  230.       for(int var6 = 0; var6 < var1.length() && var4 < var5; ++var4) {
  231.          int var7 = var1.indexOf(124, var6);
  232.          if (var7 == -1) {
  233.             var7 = var1.length();
  234.          }
  235.  
  236.          if (var6 != var7) {
  237.             int var8 = Integer.parseInt(var1.substring(var6, var7));
  238.             var3.put(new Integer(var4), new Integer(var8));
  239.          } else {
  240.             var3.put(new Integer(var4), new Integer(this.globalPause));
  241.          }
  242.  
  243.          var6 = var7 + 1;
  244.       }
  245.  
  246.       return var3;
  247.    }
  248.  
  249.    Point parsePoint(String var1) throws ParseException {
  250.       int var2 = var1.indexOf(64);
  251.       if (var2 == -1) {
  252.          throw new ParseException("Illegal position: " + var1);
  253.       } else {
  254.          return new Point(Integer.parseInt(var1.substring(0, var2)), Integer.parseInt(var1.substring(var2 + 1)));
  255.       }
  256.    }
  257.  
  258.    Hashtable parsePositions(String var1, Vector var2) throws ParseException {
  259.       Hashtable var3 = new Hashtable();
  260.       int var4 = 0;
  261.       int var5 = var2.size();
  262.  
  263.       for(int var6 = 0; var6 < var1.length() && var4 < var5; ++var4) {
  264.          int var7 = var1.indexOf(124, var6);
  265.          if (var7 == -1) {
  266.             var7 = var1.length();
  267.          }
  268.  
  269.          if (var6 != var7) {
  270.             var3.put(new Integer(var4), this.parsePoint(var1.substring(var6, var7)));
  271.          }
  272.  
  273.          var6 = var7 + 1;
  274.       }
  275.  
  276.       return var3;
  277.    }
  278.  
  279.    Dimension getImageDimensions(Image var1) {
  280.       return new Dimension(var1.getWidth((ImageObserver)null), var1.getHeight((ImageObserver)null));
  281.    }
  282.  
  283.    String doSubst(String var1, String var2) {
  284.       String var3 = "0000000000";
  285.       int var4 = var1.length();
  286.       StringBuffer var5 = new StringBuffer(var4);
  287.       int var6 = 0;
  288.  
  289.       while(var6 < var4) {
  290.          char var7 = var1.charAt(var6);
  291.          if (var7 == '%') {
  292.             ++var6;
  293.             if (var6 == var4) {
  294.                var5.append(var7);
  295.             } else {
  296.                var7 = var1.charAt(var6);
  297.                if (var7 != 'N' && var7 != 'n') {
  298.                   int var8;
  299.                   if ((var8 = Character.digit(var7, 10)) != -1) {
  300.                      String var10 = var3 + var2;
  301.                      var5.append(var10.substring(var10.length() - var8));
  302.                      ++var6;
  303.                   } else {
  304.                      var5.append(var7);
  305.                      ++var6;
  306.                   }
  307.                } else {
  308.                   var5.append(var2);
  309.                   ++var6;
  310.                }
  311.             }
  312.          } else {
  313.             var5.append(var7);
  314.             ++var6;
  315.          }
  316.       }
  317.  
  318.       return var5.toString();
  319.    }
  320.  
  321.    Vector prepareImageRange(int var1, int var2, String var3) throws MalformedURLException {
  322.       Vector var4 = new Vector(Math.abs(var2 - var1) + 1);
  323.       if (var3 == null) {
  324.          var3 = "T%N.gif";
  325.       }
  326.  
  327.       if (var1 > var2) {
  328.          for(int var5 = var1; var5 >= var2; --var5) {
  329.             var4.addElement(new URL(this.imageSource, this.doSubst(var3, var5 + "")));
  330.          }
  331.       } else {
  332.          for(int var6 = var1; var6 <= var2; ++var6) {
  333.             var4.addElement(new URL(this.imageSource, this.doSubst(var3, var6 + "")));
  334.          }
  335.       }
  336.  
  337.       return var4;
  338.    }
  339.  
  340.    public void init() {
  341.       this.tracker = new MediaTracker(this);
  342.       this.appWidth = ((Component)this).size().width;
  343.       this.appHeight = ((Component)this).size().height;
  344.  
  345.       try {
  346.          String var1 = this.getParam("IMAGESOURCE");
  347.          this.imageSource = var1 == null ? ((Applet)this).getDocumentBase() : new URL(((Applet)this).getDocumentBase(), var1 + "/");
  348.          String var2 = this.getParam("HREF");
  349.          if (var2 != null) {
  350.             try {
  351.                this.hrefURL = new URL(((Applet)this).getDocumentBase(), var2);
  352.             } catch (MalformedURLException var5) {
  353.                this.showParseError(var5);
  354.             }
  355.          }
  356.  
  357.          this.hrefTarget = this.getParam("TARGET");
  358.          if (this.hrefTarget == null) {
  359.             this.hrefTarget = "_top";
  360.          }
  361.  
  362.          var1 = this.getParam("PAUSE");
  363.          this.globalPause = var1 != null ? Integer.parseInt(var1) : 3900;
  364.          var1 = this.getParam("REPEAT");
  365.          this.repeat = var1 == null ? true : var1.equalsIgnoreCase("yes") || var1.equalsIgnoreCase("true");
  366.          int var3 = 1;
  367.          int var4 = 1;
  368.          var1 = this.getParam("ENDIMAGE");
  369.          if (var1 != null) {
  370.             var4 = Integer.parseInt(var1);
  371.             var1 = this.getParam("STARTIMAGE");
  372.             if (var1 != null) {
  373.                var3 = Integer.parseInt(var1);
  374.             }
  375.  
  376.             var1 = this.getParam("NAMEPATTERN");
  377.             this.images = this.prepareImageRange(var3, var4, var1);
  378.          } else {
  379.             var1 = this.getParam("STARTIMAGE");
  380.             if (var1 != null) {
  381.                var3 = Integer.parseInt(var1);
  382.                var1 = this.getParam("NAMEPATTERN");
  383.                this.images = this.prepareImageRange(var3, var4, var1);
  384.             } else {
  385.                var1 = this.getParam("IMAGES");
  386.                if (var1 == null) {
  387.                   ((Applet)this).showStatus("No legal IMAGES, STARTIMAGE, or ENDIMAGE specified.");
  388.                   this.error = true;
  389.                   return;
  390.                }
  391.  
  392.                this.images = this.parseImages(var1, this.getParam("NAMEPATTERN"));
  393.             }
  394.          }
  395.  
  396.          var1 = this.getParam("BACKGROUND");
  397.          if (var1 != null) {
  398.             this.backgroundImageURL = new URL(this.imageSource, var1);
  399.          }
  400.  
  401.          var1 = this.getParam("BACKGROUNDCOLOR");
  402.          if (var1 != null) {
  403.             this.backgroundColor = this.decodeColor(var1);
  404.          }
  405.  
  406.          var1 = this.getParam("STARTUP");
  407.          if (var1 != null) {
  408.             this.startUpImageURL = new URL(this.imageSource, var1);
  409.          }
  410.  
  411.          var1 = this.getParam("SOUNDSOURCE");
  412.          this.soundSource = var1 == null ? this.imageSource : new URL(((Applet)this).getDocumentBase(), var1 + "/");
  413.          var1 = this.getParam("SOUNDS");
  414.          if (var1 != null) {
  415.             this.sounds = this.parseSounds(var1, this.images);
  416.          }
  417.  
  418.          var1 = this.getParam("PAUSES");
  419.          if (var1 != null) {
  420.             this.durations = this.parseDurations(var1, this.images);
  421.          }
  422.  
  423.          var1 = this.getParam("POSITIONS");
  424.          if (var1 != null) {
  425.             this.positions = this.parsePositions(var1, this.images);
  426.          }
  427.  
  428.          var1 = this.getParam("SOUNDTRACK");
  429.          if (var1 != null) {
  430.             this.soundtrackURL = new URL(this.soundSource, var1);
  431.          }
  432.       } catch (MalformedURLException var6) {
  433.          this.showParseError(var6);
  434.       } catch (ParseException var7) {
  435.          this.showParseError(var7);
  436.       }
  437.  
  438.       this.setFrameNum(0);
  439.    }
  440.  
  441.    Color decodeColor(String var1) {
  442.       int var2 = 0;
  443.  
  444.       try {
  445.          if (var1.startsWith("0x")) {
  446.             var2 = Integer.parseInt(var1.substring(2), 16);
  447.          } else if (var1.startsWith("#")) {
  448.             var2 = Integer.parseInt(var1.substring(1), 16);
  449.          } else if (var1.startsWith("0") && var1.length() > 1) {
  450.             var2 = Integer.parseInt(var1.substring(1), 8);
  451.          } else {
  452.             var2 = Integer.parseInt(var1, 10);
  453.          }
  454.  
  455.          return new Color(var2);
  456.       } catch (NumberFormatException var3) {
  457.          return null;
  458.       }
  459.    }
  460.  
  461.    void tellLoadingMsg(String var1, String var2) {
  462.       ((Applet)this).showStatus("Animator: loading " + var2 + " " + var1);
  463.    }
  464.  
  465.    void tellLoadingMsg(URL var1, String var2) {
  466.       this.tellLoadingMsg(var1.toExternalForm(), var2);
  467.    }
  468.  
  469.    void clearLoadingMessage() {
  470.       ((Applet)this).showStatus("");
  471.    }
  472.  
  473.    void loadError(String var1, String var2) {
  474.       String var3 = "Animator: Couldn't load " + var2 + " " + var1;
  475.       ((Applet)this).showStatus(var3);
  476.       System.err.println(var3);
  477.       this.error = true;
  478.       ((Component)this).repaint();
  479.    }
  480.  
  481.    void loadError(URL var1, String var2) {
  482.       this.loadError(var1.toExternalForm(), var2);
  483.    }
  484.  
  485.    void loadErrors(Object[] var1, String var2) {
  486.       for(int var3 = 0; var3 < var1.length; ++var3) {
  487.          if (var1[var3] instanceof Image) {
  488.             URL var4 = (URL)this.imageNames.get((Image)var1[var3]);
  489.             if (var4 != null) {
  490.                this.loadError(var4, var2);
  491.             }
  492.          }
  493.       }
  494.  
  495.    }
  496.  
  497.    void showParseError(Exception var1) {
  498.       String var2 = "Animator: Parse error: " + var1;
  499.       ((Applet)this).showStatus(var2);
  500.       System.err.println(var2);
  501.       this.error = true;
  502.       ((Component)this).repaint();
  503.    }
  504.  
  505.    void startPlaying() {
  506.       if (this.soundtrack != null) {
  507.          this.soundtrack.loop();
  508.       }
  509.  
  510.    }
  511.  
  512.    void stopPlaying() {
  513.       if (this.soundtrack != null) {
  514.          this.soundtrack.stop();
  515.       }
  516.  
  517.    }
  518.  
  519.    public void run() {
  520.       Thread var1 = Thread.currentThread();
  521.       var1.setPriority(1);
  522.       if (!this.loaded) {
  523.          try {
  524.             if (this.startUpImageURL != null) {
  525.                this.tellLoadingMsg(this.startUpImageURL, "image");
  526.                this.startUpImage = this.fetchImageAndWait(this.startUpImageURL, 0);
  527.                if (this.tracker.isErrorID(0)) {
  528.                   this.loadError(this.startUpImageURL, "start-up image");
  529.                }
  530.  
  531.                ((Component)this).repaint();
  532.             }
  533.  
  534.             if (this.backgroundImageURL != null) {
  535.                this.tellLoadingMsg(this.backgroundImageURL, "image");
  536.                this.backgroundImage = this.fetchImageAndWait(this.backgroundImageURL, 1);
  537.                if (this.tracker.isErrorID(1)) {
  538.                   this.loadError(this.backgroundImageURL, "background image");
  539.                }
  540.  
  541.                ((Component)this).repaint();
  542.             }
  543.  
  544.             if (!this.fetchImages(this.images)) {
  545.                Object[] var3 = this.tracker.getErrorsAny();
  546.                this.loadErrors(var3, "image");
  547.                return;
  548.             }
  549.  
  550.             if (this.soundtrackURL != null && this.soundtrack == null) {
  551.                this.tellLoadingMsg(this.soundtrackURL, "image");
  552.                this.soundtrack = ((Applet)this).getAudioClip(this.soundtrackURL);
  553.                if (this.soundtrack == null) {
  554.                   this.loadError(this.soundtrackURL, "soundtrack");
  555.                   return;
  556.                }
  557.             }
  558.  
  559.             if (this.sounds != null) {
  560.                URL var2 = this.fetchSounds(this.sounds);
  561.                if (var2 != null) {
  562.                   this.loadError(var2, "sound");
  563.                   return;
  564.                }
  565.             }
  566.  
  567.             this.clearLoadingMessage();
  568.             this.offScrImage = ((Component)this).createImage(this.appWidth, this.appHeight);
  569.             this.offScrGC = this.offScrImage.getGraphics();
  570.             this.offScrGC.setColor(Color.lightGray);
  571.             this.loaded = true;
  572.             this.error = false;
  573.          } catch (Exception var10) {
  574.             this.error = true;
  575.             ((Throwable)var10).printStackTrace();
  576.          }
  577.       }
  578.  
  579.       if (!this.userPause) {
  580.          if (this.repeat || this.frameNum < this.images.size()) {
  581.             this.startPlaying();
  582.          }
  583.  
  584.          try {
  585.             if (this.images != null && this.images.size() > 1) {
  586.                for(; this.appWidth > 0 && this.appHeight > 0 && this.engine == var1; this.setFrameNum(this.frameNum + 1)) {
  587.                   if (this.frameNum >= this.images.size()) {
  588.                      if (!this.repeat) {
  589.                         return;
  590.                      }
  591.  
  592.                      this.setFrameNum(0);
  593.                   }
  594.  
  595.                   ((Component)this).repaint();
  596.                   if (this.sounds != null) {
  597.                      AudioClip var5 = (AudioClip)this.sounds.get(this.frameNumKey);
  598.                      if (var5 != null) {
  599.                         var5.play();
  600.                      }
  601.                   }
  602.  
  603.                   try {
  604.                      Integer var12 = null;
  605.                      if (this.durations != null) {
  606.                         var12 = (Integer)this.durations.get(this.frameNumKey);
  607.                      }
  608.  
  609.                      if (var12 == null) {
  610.                         Thread.sleep((long)this.globalPause);
  611.                      } else {
  612.                         Thread.sleep((long)var12);
  613.                      }
  614.                   } catch (InterruptedException var9) {
  615.                   }
  616.                }
  617.  
  618.             }
  619.          } finally {
  620.             this.stopPlaying();
  621.          }
  622.       }
  623.    }
  624.  
  625.    public void update(Graphics var1) {
  626.       this.paint(var1);
  627.    }
  628.  
  629.    public void paint(Graphics var1) {
  630.       if (!this.error && this.loaded) {
  631.          if (this.images != null && this.images.size() > 0 && this.tracker.checkID(2)) {
  632.             if (this.frameNum < this.images.size()) {
  633.                if (this.backgroundImage == null) {
  634.                   this.offScrGC.clearRect(0, 0, this.appWidth, this.appHeight);
  635.                } else {
  636.                   this.offScrGC.drawImage(this.backgroundImage, 0, 0, this);
  637.                }
  638.  
  639.                Image var2 = (Image)this.images.elementAt(this.frameNum);
  640.                Point var3 = null;
  641.                if (this.positions != null) {
  642.                   var3 = (Point)this.positions.get(this.frameNumKey);
  643.                }
  644.  
  645.                if (var3 != null) {
  646.                   this.xPos = var3.x;
  647.                   this.yPos = var3.y;
  648.                }
  649.  
  650.                if (this.backgroundColor != null) {
  651.                   this.offScrGC.setColor(this.backgroundColor);
  652.                   this.offScrGC.fillRect(0, 0, this.appWidth, this.appHeight);
  653.                   this.offScrGC.drawImage(var2, this.xPos, this.yPos, this.backgroundColor, this);
  654.                } else {
  655.                   this.offScrGC.drawImage(var2, this.xPos, this.yPos, this);
  656.                }
  657.  
  658.                var1.drawImage(this.offScrImage, 0, 0, this);
  659.                return;
  660.             }
  661.  
  662.             this.dbg("No more animation; drawing last image.");
  663.             if (this.backgroundImage == null) {
  664.                var1.fillRect(0, 0, this.appWidth, this.appHeight);
  665.             } else {
  666.                var1.drawImage(this.backgroundImage, 0, 0, this);
  667.             }
  668.  
  669.             var1.drawImage((Image)this.images.lastElement(), 0, 0, this);
  670.          }
  671.  
  672.       } else {
  673.          if (this.startUpImage != null) {
  674.             if (this.tracker.checkID(0)) {
  675.                if (this.backgroundColor != null) {
  676.                   var1.setColor(this.backgroundColor);
  677.                   var1.fillRect(0, 0, this.appWidth, this.appHeight);
  678.                }
  679.  
  680.                var1.drawImage(this.startUpImage, 0, 0, this);
  681.                return;
  682.             }
  683.          } else if (this.backgroundImage != null) {
  684.             if (this.tracker.checkID(1)) {
  685.                var1.drawImage(this.backgroundImage, 0, 0, this);
  686.                return;
  687.             }
  688.          } else {
  689.             var1.clearRect(0, 0, this.appWidth, this.appHeight);
  690.          }
  691.  
  692.       }
  693.    }
  694.  
  695.    public void start() {
  696.       if (this.engine == null) {
  697.          this.engine = new Thread(this);
  698.          this.engine.start();
  699.       }
  700.  
  701.       ((Applet)this).showStatus(this.getAppletInfo());
  702.    }
  703.  
  704.    public void stop() {
  705.       if (this.engine != null && this.engine.isAlive()) {
  706.          this.engine.stop();
  707.       }
  708.  
  709.       this.engine = null;
  710.    }
  711.  
  712.    public boolean handleEvent(Event var1) {
  713.       switch (var1.id) {
  714.          case 402:
  715.          case 403:
  716.          case 404:
  717.             this.dbg("Got event " + var1);
  718.             return true;
  719.          case 501:
  720.             if ((var1.modifiers & 1) != 0) {
  721.                this.showDescription();
  722.                return true;
  723.             } else if (this.hrefURL != null) {
  724.                return true;
  725.             } else {
  726.                if (this.loaded) {
  727.                   if (this.engine != null && this.engine.isAlive()) {
  728.                      if (this.userPause) {
  729.                         this.engine.resume();
  730.                         this.startPlaying();
  731.                      } else {
  732.                         this.engine.suspend();
  733.                         this.stopPlaying();
  734.                      }
  735.  
  736.                      this.userPause = !this.userPause;
  737.                   } else {
  738.                      this.userPause = false;
  739.                      this.setFrameNum(0);
  740.                      this.engine = new Thread(this);
  741.                      this.engine.start();
  742.                   }
  743.                }
  744.  
  745.                return true;
  746.             }
  747.          case 502:
  748.             if (this.hrefURL != null && (var1.modifiers & 1) == 0) {
  749.                ((Applet)this).getAppletContext().showDocument(this.hrefURL, this.hrefTarget);
  750.             }
  751.  
  752.             return true;
  753.          case 504:
  754.             ((Applet)this).showStatus(this.getAppletInfo() + " -- " + "shift-click for errors, info");
  755.             return true;
  756.          case 505:
  757.             ((Applet)this).showStatus("");
  758.             return true;
  759.          default:
  760.             return super.handleEvent(var1);
  761.       }
  762.    }
  763. }
  764.