home *** CD-ROM | disk | FTP | other *** search
/ Inside Dreamweaver 4 / IDW4.ISO / pc / Projects / ch20 / java / quote / classes / JavaQuote.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-12-07  |  2.9 KB  |  112 lines

  1. import java.applet.Applet;
  2. import java.awt.Color;
  3. import java.awt.Component;
  4. import java.awt.Dimension;
  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 JavaQuote extends Applet implements Runnable {
  12.    private Dimension size;
  13.    private Image offImage;
  14.    private Graphics offG;
  15.    private ParamParser param;
  16.    private Color bgcolor;
  17.    private Thread animate;
  18.    private long delay;
  19.    private String link;
  20.    private String target;
  21.    private TextScript script;
  22.  
  23.    public void init() {
  24.       this.size = ((Component)this).size();
  25.       this.param = new ParamParser(this);
  26.       this.bgcolor = this.param.parseColor("bgcolor", Color.white);
  27.       ((Component)this).setBackground(this.bgcolor);
  28.       this.delay = (long)this.param.parseInt("delay", 100);
  29.       this.link = this.param.parseString("link", (String)null);
  30.       this.target = this.param.parseString("target", "_self");
  31.       this.offImage = ((Component)this).createImage(this.size.width, this.size.height);
  32.       this.offG = this.offImage.getGraphics();
  33.       this.script = new TextScript(this.offG, this.param, this.size);
  34.       this.script.init();
  35.    }
  36.  
  37.    public void start() {
  38.       if (this.animate == null || !this.animate.isAlive()) {
  39.          this.animate = new Thread(this);
  40.       }
  41.  
  42.       this.animate.start();
  43.       this.script.start();
  44.    }
  45.  
  46.    public void run() {
  47.       while(Thread.currentThread() == this.animate) {
  48.          try {
  49.             this.script.update();
  50.             ((Component)this).repaint();
  51.             Thread.sleep(this.delay);
  52.          } catch (InterruptedException var2) {
  53.             ((Throwable)var2).printStackTrace();
  54.          }
  55.       }
  56.  
  57.    }
  58.  
  59.    public void stop() {
  60.       if (this.animate != null && this.animate.isAlive()) {
  61.          this.script.stop();
  62.          this.animate.stop();
  63.       }
  64.  
  65.    }
  66.  
  67.    public void destroy() {
  68.       this.animate = null;
  69.    }
  70.  
  71.    public void update(Graphics var1) {
  72.       this.script.paint(this.offG);
  73.       this.paint(var1);
  74.    }
  75.  
  76.    public void paint(Graphics var1) {
  77.       var1.drawImage(this.offImage, 0, 0, this);
  78.    }
  79.  
  80.    public boolean mouseDown(Event var1, int var2, int var3) {
  81.       if (this.link != null) {
  82.          try {
  83.             URL var4 = new URL(((Applet)this).getDocumentBase(), this.link);
  84.             ((Applet)this).getAppletContext().showDocument(var4, this.target);
  85.             if (this.target.equals("_self")) {
  86.                this.stop();
  87.             }
  88.          } catch (MalformedURLException var5) {
  89.             ((Throwable)var5).printStackTrace();
  90.          }
  91.       }
  92.  
  93.       return true;
  94.    }
  95.  
  96.    public boolean mouseEnter(Event var1, int var2, int var3) {
  97.       if (this.link != null) {
  98.          ((Applet)this).showStatus(this.link);
  99.       }
  100.  
  101.       return true;
  102.    }
  103.  
  104.    public boolean mouseExit(Event var1, int var2, int var3) {
  105.       if (this.link != null) {
  106.          ((Applet)this).showStatus("");
  107.       }
  108.  
  109.       return true;
  110.    }
  111. }
  112.