home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2003 January / maximum-cd-2003-01.iso / Software / Utilities / JPerk / jperk.exe / _SETUP.1 / Lake.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-02-25  |  4.7 KB  |  225 lines

  1. import java.applet.Applet;
  2. import java.awt.Component;
  3. import java.awt.Event;
  4. import java.awt.Graphics;
  5. import java.awt.Image;
  6. import java.awt.MediaTracker;
  7. import java.net.MalformedURLException;
  8. import java.net.URL;
  9.  
  10. public class Lake extends Applet implements Runnable {
  11.    Thread m_Lake;
  12.    private Graphics m_Graphics;
  13.    private Graphics m_WaveGraphics;
  14.    private Image m_Image;
  15.    private Image m_Overlay;
  16.    private Image m_WaveImage;
  17.    private int m_nCurrImage;
  18.    private int m_nImgWidth;
  19.    private int m_nImgHeight;
  20.    private int m_nOvlWidth;
  21.    private int m_nOvlHeight;
  22.    private boolean m_fAllLoaded;
  23.    private boolean m_tAnimate = true;
  24.    private final int NUM_FRAMES = 12;
  25.    private String m_ImageName = "";
  26.    private String m_OverlayName = "";
  27.    private URL m_HRef;
  28.    private String m_Frame = "_self";
  29.    private final String PARAM_image = "image";
  30.    private final String PARAM_overlay = "overlay";
  31.    private final String PARAM_href = "href";
  32.    private final String PARAM_target = "target";
  33.  
  34.    public void createAnimation() {
  35.       Image var1 = ((Component)this).createImage(this.m_nImgWidth, this.m_nImgHeight + 1);
  36.       Graphics var2 = var1.getGraphics();
  37.       var2.drawImage(this.m_Image, 0, 1, this);
  38.  
  39.       for(int var3 = 0; var3 < this.m_nImgHeight >> 1; ++var3) {
  40.          var2.copyArea(0, var3, this.m_nImgWidth, 1, 0, this.m_nImgHeight - var3);
  41.          var2.copyArea(0, this.m_nImgHeight - 1 - var3, this.m_nImgWidth, 1, 0, -this.m_nImgHeight + 1 + (var3 << 1));
  42.          var2.copyArea(0, this.m_nImgHeight, this.m_nImgWidth, 1, 0, -1 - var3);
  43.       }
  44.  
  45.       this.m_WaveImage = ((Component)this).createImage(13 * this.m_nImgWidth, this.m_nImgHeight);
  46.       this.m_WaveGraphics = this.m_WaveImage.getGraphics();
  47.       this.m_WaveGraphics.drawImage(var1, 12 * this.m_nImgWidth, 0, this);
  48.       int var5 = 0;
  49.  
  50.       do {
  51.          this.makeWaves(this.m_WaveGraphics, var5);
  52.          ++var5;
  53.       } while(var5 < 12);
  54.  
  55.       var2.drawImage(this.m_Image, 0, 1, this);
  56.       if (!"".equals(this.m_OverlayName)) {
  57.          var2.drawImage(this.m_Overlay, this.m_nImgWidth - this.m_nOvlWidth >> 1, this.m_nImgHeight - (this.m_nOvlHeight >> 1), this);
  58.       }
  59.  
  60.       this.m_Image = var1;
  61.    }
  62.  
  63.    public void start() {
  64.       if (this.m_Lake == null) {
  65.          this.m_Lake = new Thread(this);
  66.          this.m_Lake.start();
  67.       }
  68.  
  69.    }
  70.  
  71.    public String[][] getParameterInfo() {
  72.       String[][] var1 = new String[][]{{"image", "String", "JPG or GIF file to reflect"}, {"overlay", "String", "JPG or GIF file to use as overlay"}, {"href", "URL", "URL to link to"}, {"target", "String", "Target frame"}};
  73.       return var1;
  74.    }
  75.  
  76.    public void stop() {
  77.       if (this.m_Lake != null) {
  78.          this.m_Lake.stop();
  79.          this.m_Lake = null;
  80.       }
  81.  
  82.    }
  83.  
  84.    private void displayImage(Graphics var1) {
  85.       if (this.m_fAllLoaded) {
  86.          if (this.m_WaveImage != null) {
  87.             var1.drawImage(this.m_WaveImage, -this.m_nCurrImage * this.m_nImgWidth, this.m_nImgHeight, this);
  88.             var1.drawImage(this.m_WaveImage, (12 - this.m_nCurrImage) * this.m_nImgWidth, this.m_nImgHeight, this);
  89.          }
  90.  
  91.          var1.drawImage(this.m_Image, 0, -1, this);
  92.       }
  93.    }
  94.  
  95.    public String getAppletInfo() {
  96.       return "Name: Lake v3.0\r\n" + "Author: David Griffiths\r\n" + "Created with Microsoft Visual J++ Version 1.0";
  97.    }
  98.  
  99.    public boolean mouseUp(Event var1, int var2, int var3) {
  100.       super.mouseUp(var1, var2, var3);
  101.       if (this.m_HRef == null) {
  102.          this.m_tAnimate = !this.m_tAnimate;
  103.       } else {
  104.          ((Applet)this).showStatus("" + this.m_HRef);
  105.          ((Applet)this).getAppletContext().showDocument(this.m_HRef, this.m_Frame);
  106.       }
  107.  
  108.       return true;
  109.    }
  110.  
  111.    public void run() {
  112.       this.m_nCurrImage = 0;
  113.       if (!this.m_fAllLoaded) {
  114.          ((Component)this).repaint();
  115.          this.m_Graphics = ((Component)this).getGraphics();
  116.          MediaTracker var1 = new MediaTracker(this);
  117.          this.m_Image = ((Applet)this).getImage(((Applet)this).getDocumentBase(), this.m_ImageName);
  118.          if (!"".equals(this.m_OverlayName)) {
  119.             this.m_Overlay = ((Applet)this).getImage(((Applet)this).getDocumentBase(), this.m_OverlayName);
  120.          }
  121.  
  122.          var1.addImage(this.m_Image, 0);
  123.          if (!"".equals(this.m_OverlayName)) {
  124.             var1.addImage(this.m_Overlay, 1);
  125.          }
  126.  
  127.          try {
  128.             var1.waitForAll();
  129.             this.m_fAllLoaded = !var1.isErrorAny();
  130.          } catch (InterruptedException var3) {
  131.          }
  132.  
  133.          if (!this.m_fAllLoaded) {
  134.             this.stop();
  135.             this.m_Graphics.drawString("Error loading images!", 10, 40);
  136.             return;
  137.          }
  138.  
  139.          this.m_nImgWidth = this.m_Image.getWidth(this);
  140.          this.m_nImgHeight = this.m_Image.getHeight(this);
  141.          if (!"".equals(this.m_OverlayName)) {
  142.             this.m_nOvlWidth = this.m_Overlay.getWidth(this);
  143.             this.m_nOvlHeight = this.m_Overlay.getHeight(this);
  144.          }
  145.  
  146.          this.createAnimation();
  147.       }
  148.  
  149.       ((Component)this).repaint();
  150.  
  151.       while(true) {
  152.          try {
  153.             for(; this.m_tAnimate; Thread.sleep(50L)) {
  154.                this.displayImage(this.m_Graphics);
  155.                if (++this.m_nCurrImage == 12) {
  156.                   this.m_nCurrImage = 0;
  157.                }
  158.             }
  159.  
  160.             Thread.sleep(500L);
  161.          } catch (InterruptedException var4) {
  162.             this.stop();
  163.          }
  164.       }
  165.    }
  166.  
  167.    public void makeWaves(Graphics var1, int var2) {
  168.       double var3 = (Math.PI * 2D) * (double)var2 / (double)12.0F;
  169.       int var5 = (12 - var2) * this.m_nImgWidth;
  170.  
  171.       for(int var7 = 0; var7 < this.m_nImgHeight; ++var7) {
  172.          int var6 = (int)((double)(this.m_nImgHeight / 14) * ((double)var7 + (double)28.0F) * Math.sin((double)(this.m_nImgHeight / 14 * (this.m_nImgHeight - var7)) / (double)(var7 + 1) + var3) / (double)this.m_nImgHeight);
  173.          if (var7 < -var6) {
  174.             var1.copyArea(12 * this.m_nImgWidth, var7, this.m_nImgWidth, 1, -var5, 0);
  175.          } else {
  176.             var1.copyArea(12 * this.m_nImgWidth, var7 + var6, this.m_nImgWidth, 1, -var5, -var6);
  177.          }
  178.       }
  179.  
  180.       if (!"".equals(this.m_OverlayName)) {
  181.          var1.drawImage(this.m_Overlay, var2 * this.m_nImgWidth + (this.m_nImgWidth - this.m_nOvlWidth >> 1), -this.m_nOvlHeight >> 1, this);
  182.       }
  183.  
  184.    }
  185.  
  186.    public void destroy() {
  187.    }
  188.  
  189.    public void init() {
  190.       String var1 = ((Applet)this).getParameter("image");
  191.       if (var1 != null) {
  192.          this.m_ImageName = var1;
  193.       }
  194.  
  195.       var1 = ((Applet)this).getParameter("overlay");
  196.       if (var1 != null) {
  197.          this.m_OverlayName = var1;
  198.       }
  199.  
  200.       var1 = ((Applet)this).getParameter("href");
  201.       if (var1 != null) {
  202.          try {
  203.             this.m_HRef = new URL(((Applet)this).getDocumentBase(), var1);
  204.          } catch (MalformedURLException var3) {
  205.             ((Applet)this).getAppletContext().showStatus("Bad URL: " + var1);
  206.             return;
  207.          }
  208.       }
  209.  
  210.       var1 = ((Applet)this).getParameter("target");
  211.       if (var1 != null) {
  212.          this.m_Frame = var1;
  213.       }
  214.  
  215.    }
  216.  
  217.    public void paint(Graphics var1) {
  218.       if (this.m_fAllLoaded) {
  219.          this.displayImage(var1);
  220.       } else {
  221.          var1.drawString("Loading images...", 10, 20);
  222.       }
  223.    }
  224. }
  225.