/* * StdApplet.java * * Copyright (C) 1996 Shaun Terry. All Rights Reserved. */ package spt.applets; import java.awt.Event; import java.util.Enumeration; import java.applet.*; import spt.applets.AppletParamParser; /** * Some useful applet-related behavior not provided by the Applet class. * This class should be subclassed instead of Applet. * * Parameters *
 * BGColor		Color	Background color (optional)
 * FGColor		Color	Foreground color (optional)
 * HelpText	String	A status message to display when the mouse is over the applet (optional)
 *
 * 
* * @see java.applet.Applet * @author Shaun Terry */ public class StdApplet extends Applet { protected boolean fDebug = false; protected String helpText; // Want this to be protected but compiler has bug public AppletParamParser paramParser; /** General initialization. Most applets will override this * method so they should be sure to call super.init() as the * first action in their own init(). */ public void init() { stdAppletInit(); } /** General initialization. This exists mainly for classes * that for whatever reason can't call super.init(). */ public void stdAppletInit() { paramParser = new AppletParamParser(this); paramParser.applyFGBGColorParam(); fDebug = paramParser.getBoolean("DEBUG", false).booleanValue(); String text; if ((text = getParameter("HELPTEXT")) != null) { setHelpText(text); } } /** Gets an applet by name. Same as AppletContext.getApplet() but * works better under Netscape. * @see java.applet.AppletContext#getApplet */ public Applet getApplet(String s) { // return getAppletContext().getApplet(s); // Cuz Netscape is broken! Enumeration en = getAppletContext().getApplets(); for (; en.hasMoreElements();) { Applet o = (Applet) en.nextElement(); if (o != null) { // Should never happen but it does sometimes?! String name = o.getParameter("name"); if (name != null && name.equals(s)) return o; } } return null; } /** Sets the help message. Help messages are displayed when the * mouse is moved over an applet. */ public void setHelpText(String t) { helpText = t; } public String getHelpText() { return helpText; } public boolean mouseEnter(Event e, int x, int y) { if (helpText != null) showStatus(helpText); return true; } public boolean mouseExit(Event e, int x, int y) { if (helpText != null) showStatus(""); return true; } /** Returns a default authorship string. Applets can override * this to get special messages. */ public String getAppletInfo() { return getClass().getName() + " by Shaun Terry (72010.1771@compuserve.com). Copyright (C) 1996. All Rights Reserved."; } /** Parameters */ public String[][] getParameterInfo() { String[][] info = { { "BGColor", "Color", "Background color (optional)" }, { "FGColor", "Color", "Foreground color (optional)" }, { "HelpText", "String", "A status message to display when the mouse is over the applet (optional)" }, // { "EnterAudio", "URL", "Audio to play on mouse enter (optional)" }, }; return info; } /** Combine two lists of parameters. Subclasses can use this * method to combine their parameters with those of their * parent. */ public static String[][] mergeParameters(String[][] s1, String[][] s2) { String s3[][] = new String[s1.length + s2.length][]; System.arraycopy(s1, 0, s3, 0, s1.length); System.arraycopy(s2, 0, s3, s1.length, s2.length); return s3; } }