home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / dek17tau / classes / spt / applets / stdapplet.java < prev   
Encoding:
Java Source  |  1996-08-14  |  3.5 KB  |  131 lines

  1.  
  2. /*
  3.  * StdApplet.java
  4.  *
  5.  * Copyright (C) 1996 Shaun Terry. All Rights Reserved.
  6.  */
  7.  
  8. package spt.applets;
  9.  
  10. import java.awt.Event;
  11. import java.util.Enumeration;
  12. import java.applet.*;
  13.  
  14. import spt.applets.AppletParamParser;
  15.  
  16.  
  17. /**
  18.  * Some useful applet-related behavior not provided by the Applet class.
  19.  * This class should be subclassed instead of Applet.
  20.  *
  21.  * <strong>Parameters</strong>
  22.  * <pre>
  23.  * BGColor        Color    Background color (optional)
  24.  * FGColor        Color    Foreground color (optional)
  25.  * HelpText    String    A status message to display when the mouse is over the applet (optional)
  26.  *
  27.  * </pre>
  28.  *
  29.  * @see java.applet.Applet
  30.  * @author Shaun Terry
  31.  */
  32.  
  33. public class StdApplet extends Applet {
  34.  
  35.     protected boolean fDebug = false;
  36.     protected String helpText;
  37.     // Want this to be protected but compiler has bug
  38.     public AppletParamParser paramParser;
  39.  
  40.     /** General initialization. Most applets will override this
  41.      *    method so they should be sure to call super.init() as the
  42.      *    first action in their own init().
  43.      */
  44.     public void init() {
  45.         stdAppletInit();
  46.        }
  47.  
  48.     /** General initialization. This exists mainly for classes
  49.      *    that for whatever reason can't call super.init().
  50.      */
  51.     public void stdAppletInit() {
  52.         paramParser = new AppletParamParser(this);
  53.  
  54.         paramParser.applyFGBGColorParam();
  55.  
  56.         fDebug = paramParser.getBoolean("DEBUG", false).booleanValue();
  57.  
  58.         String text;
  59.  
  60.         if ((text = getParameter("HELPTEXT")) != null) {
  61.             setHelpText(text);
  62.         }
  63.     }
  64.  
  65.     /** Gets an applet by name. Same as AppletContext.getApplet() but
  66.      *    works better under Netscape.
  67.      * @see java.applet.AppletContext#getApplet
  68.      */
  69.     public Applet getApplet(String s) {
  70. //        return getAppletContext().getApplet(s);
  71.  
  72.         // Cuz Netscape is broken!
  73.         Enumeration en = getAppletContext().getApplets();
  74.         for (; en.hasMoreElements();) {
  75.             Applet o = (Applet) en.nextElement();
  76.  
  77.             if (o != null) {    // Should never happen but it does sometimes?!
  78.                 String name = o.getParameter("name");
  79.                 if (name != null && name.equals(s)) return o;
  80.             }
  81.         }
  82.         return null;
  83.     }
  84.  
  85.     /** Sets the help message. Help messages are displayed when the
  86.      *    mouse is moved over an applet.
  87.      */
  88.     public void setHelpText(String t) { helpText = t; }
  89.  
  90.     public String getHelpText() { return helpText; }
  91.  
  92.     public boolean mouseEnter(Event e, int x, int y) {
  93.         if (helpText != null) showStatus(helpText);
  94.         return true;
  95.     }
  96.  
  97.     public boolean mouseExit(Event e, int x, int y) {
  98.         if (helpText != null) showStatus("");
  99.         return true;
  100.     }
  101.  
  102.     /** Returns a default authorship string. Applets can override
  103.      *    this to get special messages.
  104.      */
  105.     public String getAppletInfo() {
  106.         return getClass().getName() + " by Shaun Terry (72010.1771@compuserve.com). Copyright (C) 1996. All Rights Reserved.";
  107.     }
  108.  
  109.     /** Parameters */
  110.     public String[][] getParameterInfo() {
  111.         String[][] info = {
  112.             { "BGColor",    "Color",     "Background color (optional)" },
  113.             { "FGColor",    "Color",     "Foreground color (optional)" },
  114.             { "HelpText",    "String",     "A status message to display when the mouse is over the applet (optional)" },
  115. //            { "EnterAudio",    "URL",         "Audio to play on mouse enter (optional)" },
  116.         };
  117.         return info;
  118.     }
  119.  
  120.     /** Combine two lists of parameters. Subclasses can use this
  121.      *    method to combine their parameters with those of their
  122.      *    parent.
  123.      */
  124.     public static String[][] mergeParameters(String[][] s1, String[][] s2) {
  125.         String s3[][] = new String[s1.length + s2.length][];
  126.         System.arraycopy(s1, 0, s3, 0, s1.length);
  127.         System.arraycopy(s2, 0, s3, s1.length, s2.length);
  128.         return s3;
  129.     }
  130. }
  131.