home *** CD-ROM | disk | FTP | other *** search
/ Popular Software (Premium Edition) / mycd.iso / TOOLS / SAFECLEA / FILEDATA.DAT / develop / safecln / final / html / CoolBtn.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-08-08  |  3.7 KB  |  157 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.Font;
  7. import java.awt.Graphics;
  8. import java.awt.Image;
  9. import java.awt.Point;
  10. import java.net.MalformedURLException;
  11. import java.net.URL;
  12.  
  13. public class CoolBtn extends Applet implements Runnable {
  14.    Thread m_CoolBtn;
  15.    private Image m_imgMouseIn;
  16.    private Image m_imgMouseOut;
  17.    private Image m_imgMouseDown;
  18.    private int m_bBackR;
  19.    private int m_bBackG;
  20.    private int m_bBackB;
  21.    private Font m_fontFace;
  22.    private Point m_ptImg;
  23.    private Point m_ptFaceText;
  24.    private boolean m_bMouseIn;
  25.    private boolean m_bMouseDown;
  26.    private String m_FaceText = "";
  27.    private URL m_URL;
  28.    private String m_strTarget = "";
  29.    private int m_nBackR;
  30.    private int m_nBackG;
  31.    private int m_nBackB;
  32.    private final String PARAM_FaceText = "FaceText";
  33.    private final String PARAM_URL = "URL";
  34.    private final String PARAM_TARGET = "Target";
  35.    private final String PARAM_BACKR = "R";
  36.    private final String PARAM_BACKG = "G";
  37.    private final String PARAM_BACKB = "B";
  38.  
  39.    public String getAppletInfo() {
  40.       return "Name: CoolBtn\r\nAuthor: Yuheng Zhao & Dazhi Liu";
  41.    }
  42.  
  43.    public String[][] getParameterInfo() {
  44.       String[][] var1 = new String[][]{{"FaceText", "String", "Face Text"}, {"URL", "String", "URL"}, {"Target", "Target", "Target"}};
  45.       return var1;
  46.    }
  47.  
  48.    public void init() {
  49.       String var1 = ((Applet)this).getParameter("FaceText");
  50.       this.m_FaceText = var1;
  51.       var1 = ((Applet)this).getParameter("Target");
  52.       this.m_strTarget = var1;
  53.       var1 = ((Applet)this).getParameter("R");
  54.       this.m_nBackR = Integer.parseInt(var1);
  55.       var1 = ((Applet)this).getParameter("G");
  56.       this.m_nBackG = Integer.parseInt(var1);
  57.       var1 = ((Applet)this).getParameter("B");
  58.       this.m_nBackB = Integer.parseInt(var1);
  59.  
  60.       try {
  61.          var1 = ((Applet)this).getParameter("URL");
  62.          if (var1 != null) {
  63.             this.m_URL = new URL(((Applet)this).getDocumentBase(), var1);
  64.          }
  65.       } catch (MalformedURLException var3) {
  66.       }
  67.  
  68.       this.m_imgMouseIn = ((Applet)this).getImage(((Applet)this).getDocumentBase(), "images/mouseIn.gif");
  69.       this.m_imgMouseOut = ((Applet)this).getImage(((Applet)this).getDocumentBase(), "images/mouseOut.gif");
  70.       this.m_imgMouseDown = ((Applet)this).getImage(((Applet)this).getDocumentBase(), "images/mouseDown.gif");
  71.       this.m_fontFace = new Font("Arial", 1, 14);
  72.       this.m_bMouseIn = false;
  73.       this.m_bMouseDown = false;
  74.       ((Component)this).setBackground(new Color(this.m_nBackR, this.m_nBackG, this.m_nBackB));
  75.       Dimension var2 = ((Component)this).size();
  76.       this.m_ptImg = new Point(10, (var2.height - 10) / 2);
  77.       this.m_ptFaceText = new Point(26, var2.height / 2 + 5);
  78.    }
  79.  
  80.    public void destroy() {
  81.    }
  82.  
  83.    public void paint(Graphics var1) {
  84.       if (this.m_bMouseIn) {
  85.          if (this.m_bMouseDown) {
  86.             var1.drawImage(this.m_imgMouseDown, this.m_ptImg.x, this.m_ptImg.y, this);
  87.             var1.setColor(new Color(128, 0, 0));
  88.          } else {
  89.             var1.drawImage(this.m_imgMouseIn, this.m_ptImg.x, this.m_ptImg.y, this);
  90.             var1.setColor(new Color(255, 0, 0));
  91.          }
  92.       } else {
  93.          var1.drawImage(this.m_imgMouseOut, this.m_ptImg.x, this.m_ptImg.y, this);
  94.          var1.setColor(new Color(0, 0, 0));
  95.       }
  96.  
  97.       var1.setFont(this.m_fontFace);
  98.       var1.drawString(this.m_FaceText, this.m_ptFaceText.x, this.m_ptFaceText.y);
  99.    }
  100.  
  101.    public void start() {
  102.       if (this.m_CoolBtn == null) {
  103.          this.m_CoolBtn = new Thread(this);
  104.          this.m_CoolBtn.start();
  105.       }
  106.  
  107.    }
  108.  
  109.    public void stop() {
  110.       if (this.m_CoolBtn != null) {
  111.          this.m_CoolBtn.stop();
  112.          this.m_CoolBtn = null;
  113.       }
  114.  
  115.    }
  116.  
  117.    public void run() {
  118.    }
  119.  
  120.    public boolean mouseDown(Event var1, int var2, int var3) {
  121.       this.m_bMouseIn = true;
  122.       this.m_bMouseDown = true;
  123.       ((Component)this).repaint();
  124.       return true;
  125.    }
  126.  
  127.    public boolean mouseUp(Event var1, int var2, int var3) {
  128.       this.m_bMouseIn = true;
  129.       this.m_bMouseDown = false;
  130.       ((Component)this).repaint();
  131.       if (this.m_URL != null) {
  132.          if (this.m_strTarget != null) {
  133.             ((Applet)this).getAppletContext().showDocument(this.m_URL, this.m_strTarget);
  134.          } else {
  135.             ((Applet)this).getAppletContext().showDocument(this.m_URL, "_self");
  136.          }
  137.       }
  138.  
  139.       return true;
  140.    }
  141.  
  142.    public boolean mouseEnter(Event var1, int var2, int var3) {
  143.       this.m_bMouseIn = true;
  144.       this.m_bMouseDown = false;
  145.       ((Component)this).repaint();
  146.       ((Applet)this).showStatus(this.m_URL.toString());
  147.       return true;
  148.    }
  149.  
  150.    public boolean mouseExit(Event var1, int var2, int var3) {
  151.       this.m_bMouseIn = false;
  152.       this.m_bMouseDown = false;
  153.       ((Component)this).repaint();
  154.       return true;
  155.    }
  156. }
  157.