home *** CD-ROM | disk | FTP | other *** search
/ .net 1999 January - Disc 2 / NET53B.iso / pc / netcall / dynimg.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-11-06  |  3.6 KB  |  186 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.Event;
  6. import java.awt.Graphics;
  7. import java.awt.Image;
  8. import java.net.MalformedURLException;
  9. import java.net.URL;
  10.  
  11. public class dynimg extends Applet implements Runnable {
  12.    AudioClip sndclicked;
  13.    AudioClip sndactive;
  14.    Color bgColor = ((Component)this).getBackground();
  15.    Image imginact;
  16.    Image imgact;
  17.    Image imgclicked;
  18.    Image imgcurrent;
  19.    String href;
  20.    String target;
  21.    Thread running;
  22.  
  23.    public void init() {
  24.       String var1 = ((Applet)this).getParameter("bgcolor");
  25.       if (var1 != null) {
  26.          this.bgColor = this.convColor(var1);
  27.          ((Component)this).setBackground(this.bgColor);
  28.       }
  29.  
  30.       var1 = ((Applet)this).getParameter("url");
  31.       if (var1 != null) {
  32.          this.href = var1;
  33.       }
  34.  
  35.       var1 = ((Applet)this).getParameter("target");
  36.       if (var1 != null) {
  37.          this.target = var1;
  38.       }
  39.  
  40.       var1 = ((Applet)this).getParameter("inactive_image");
  41.       if (var1 != null) {
  42.          this.imginact = ((Applet)this).getImage(((Applet)this).getCodeBase(), var1);
  43.       }
  44.  
  45.       var1 = ((Applet)this).getParameter("active_image");
  46.       if (var1 != null) {
  47.          this.imgact = ((Applet)this).getImage(((Applet)this).getCodeBase(), var1);
  48.       }
  49.  
  50.       var1 = ((Applet)this).getParameter("clicked_image");
  51.       if (var1 != null) {
  52.          this.imgclicked = ((Applet)this).getImage(((Applet)this).getCodeBase(), var1);
  53.       }
  54.  
  55.       var1 = ((Applet)this).getParameter("clicked_sound");
  56.       if (var1 != null) {
  57.          this.sndclicked = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), var1);
  58.       }
  59.  
  60.       var1 = ((Applet)this).getParameter("active_sound");
  61.       if (var1 != null) {
  62.          this.sndactive = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), var1);
  63.       }
  64.  
  65.    }
  66.  
  67.    public void start() {
  68.       if (this.running == null) {
  69.          this.running = new Thread(this);
  70.          this.running.start();
  71.       }
  72.  
  73.    }
  74.  
  75.    public void stop() {
  76.       if (this.running != null) {
  77.          this.running.stop();
  78.          this.running = null;
  79.       }
  80.  
  81.    }
  82.  
  83.    public void run() {
  84.       this.imgcurrent = this.imginact;
  85.       ((Component)this).repaint();
  86.       ((Applet)this).getAppletContext().showStatus("Dynamic Image, Copyright (c) 1996 Nick Heinle");
  87.  
  88.       try {
  89.          Thread.sleep(2000L);
  90.       } catch (InterruptedException var1) {
  91.       }
  92.  
  93.       ((Applet)this).getAppletContext().showStatus("");
  94.    }
  95.  
  96.    public boolean mouseDown(Event var1, int var2, int var3) {
  97.       if (this.imgclicked != null) {
  98.          this.imgcurrent = this.imgclicked;
  99.          ((Component)this).repaint();
  100.       }
  101.  
  102.       if (this.sndclicked != null) {
  103.          this.sndclicked.play();
  104.       }
  105.  
  106.       return true;
  107.    }
  108.  
  109.    public boolean mouseUp(Event var1, int var2, int var3) {
  110.       if (this.imgact != null) {
  111.          this.imgcurrent = this.imgact;
  112.          ((Component)this).repaint();
  113.       }
  114.  
  115.       if (this.href != null) {
  116.          try {
  117.             URL var4 = new URL(((Applet)this).getDocumentBase(), this.href);
  118.             if (this.target != null) {
  119.                ((Applet)this).getAppletContext().showDocument(var4, this.target);
  120.             } else {
  121.                ((Applet)this).getAppletContext().showDocument(var4);
  122.             }
  123.          } catch (MalformedURLException var5) {
  124.          }
  125.       }
  126.  
  127.       return true;
  128.    }
  129.  
  130.    public boolean mouseEnter(Event var1, int var2, int var3) {
  131.       if (this.imgact != null) {
  132.          this.imgcurrent = this.imgact;
  133.          ((Component)this).repaint();
  134.       }
  135.  
  136.       if (this.sndactive != null) {
  137.          this.sndactive.play();
  138.       }
  139.  
  140.       if (this.href != null) {
  141.          ((Applet)this).getAppletContext().showStatus(this.href);
  142.       }
  143.  
  144.       return true;
  145.    }
  146.  
  147.    public boolean mouseExit(Event var1, int var2, int var3) {
  148.       if (this.imginact != null) {
  149.          this.imgcurrent = this.imginact;
  150.          ((Component)this).repaint();
  151.       }
  152.  
  153.       if (this.href != null) {
  154.          ((Applet)this).getAppletContext().showStatus("");
  155.       }
  156.  
  157.       return true;
  158.    }
  159.  
  160.    Color convColor(String var1) {
  161.       int var2 = 0;
  162.  
  163.       try {
  164.          if (var1.startsWith("#")) {
  165.             var2 = Integer.parseInt(var1.substring(1), 16);
  166.          } else if (var1.startsWith("0") && var1.length() > 1) {
  167.             var2 = Integer.parseInt(var1.substring(1), 8);
  168.          } else {
  169.             var2 = Integer.parseInt(var1, 10);
  170.          }
  171.  
  172.          return new Color(var2);
  173.       } catch (NumberFormatException var3) {
  174.          return null;
  175.       }
  176.    }
  177.  
  178.    public void paint(Graphics var1) {
  179.       var1.drawImage(this.imgcurrent, 0, 0, this);
  180.    }
  181.  
  182.    public void update(Graphics var1) {
  183.       this.paint(var1);
  184.    }
  185. }
  186.