<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">//******************************************************************************
// fjMenu.java:	Applet
//
// written by Wiebe de Jong (August 7, 1997)
//
// Aug8/97      parameters for font name, style and size added
// Aug11/97     parameter menu default added
// Aug11/97     parameters for centerHoriz &amp; centerVert added
// Aug11/97     menuStyle 1 &amp; 2 added
// Aug19/97     parameters for labelDefault, labelPrefix and labelSuffix added
// Aug19/97     variable parameter for label_n added
// Aug21/97     parameter target default added
//
//******************************************************************************
import java.util.*;
import java.applet.*;
import java.awt.*;

//==============================================================================
// Main Class for applet fjMenu
//
//==============================================================================
public class fjMenu extends Applet
{
    // PARAMETER SUPPORT:
    //      Parameters allow an HTML author to pass information to the applet;
    // the HTML author specifies them using the &lt;PARAM&gt; tag within the &lt;APPLET&gt;
    // tag.  The following variables are used to store the values of the
    // parameters.
    //--------------------------------------------------------------------------

    // Members for applet parameters
    // &lt;type&gt;   &lt;MemberVar&gt;     = &lt;Default Value&gt;
    //--------------------------------------------------------------------------
    private Color m_bgColor = Color.lightGray;
    private Color m_lnColor = Color.black;
    private Color m_itemColor = Color.black;
    private Color m_selectColor = Color.red;
    private Color m_fontColor = Color.white;
    private Color m_fontselColor = Color.black;
    private String m_fontName = "Helvetica";
    private int m_fontStyle = Font.PLAIN; // 0=PLAIN 1=BOLD 2=ITALIC
    private int m_fontSize = 14;
    private int m_menuStyle = 0;
    private int m_menuDefault = 0;
    private boolean m_centerHoriz = false;
    private boolean m_centerVert = true;
    private String m_labelDefault = "";
    private String m_labelPrefix = "";
    private String m_labelSuffix = "";
    private String m_targetDefault = "";
    private int m_numItems = 0;
    // 0=horizontal rectangle
    // 1=horizontal oval
    // 2=horizontal rounded rectangle
    // =vertical plain 
    // =horizontal tabs up 
    // =horizontal tabs down
    // text_1, url_1, target_1, label_1 selectColor_1, fontselColor_1

    // Parameter names.  To change a name of a parameter, you need only make
    // a single change.  Simply modify the value of the parameter string below.
    //--------------------------------------------------------------------------
    private final String PARAM_bgColor = "bgColor";
    private final String PARAM_lnColor = "lnColor";
    private final String PARAM_itemColor = "itemColor";
    private final String PARAM_selectColor = "selectColor";
    private final String PARAM_fontColor = "fontColor";
    private final String PARAM_fontselColor = "fontselColor";
    private final String PARAM_fontName = "fontName";
    private final String PARAM_fontStyle = "fontStyle"; 
    private final String PARAM_fontSize = "fontSize";
    private final String PARAM_menuStyle = "menuStyle";
    private final String PARAM_menuDefault = "menuDefault";
    private final String PARAM_centerHoriz = "centerHoriz";
    private final String PARAM_centerVert = "centerVert";
    private final String PARAM_labelDefault = "labelDefault";
    private final String PARAM_labelPrefix = "labelPrefix";
    private final String PARAM_labelSuffix = "labelSuffix";
    private final String PARAM_targetDefault = "targetDefault";
    private final String PARAM_numItems = "numItems";

    // OTHER VARIABLES:
    //--------------------------------------------------------------------------
    Font fontFont;
    FontMetrics fontMetrics;
    fjMenuItem curItem;
    boolean itemSelected;
    boolean appletActive;
    Vector items;

    // fjMenu Class Constructor
    //--------------------------------------------------------------------------
    public fjMenu()
    {
        // TODO: Add constructor code here
        items = new Vector();
        itemSelected = false;
        appletActive = false;
    }

    // APPLET INFO SUPPORT:
    //		The getAppletInfo() method returns a string describing the applet's
    // author, copyright date, or miscellaneous information.
    //--------------------------------------------------------------------------
    public String getAppletInfo()
    {
        return "Name: fjMenu\r\n" +
            "Author: Wiebe de Jong\r\n" +
            "Created with Microsoft Visual J++ Version 1.1";
    }

    // PARAMETER SUPPORT
    //      The getParameterInfo() method returns an array of strings describing
    // the parameters understood by this applet.
    //
    // fjMenu Parameter Information:
    //  { "Name", "Type", "Description" },
    //--------------------------------------------------------------------------
    public String[][] getParameterInfo()
    {
        String[][] info =
        {
            { PARAM_bgColor, "Color", "background color" },
            { PARAM_lnColor, "Color", "line color" },
            { PARAM_itemColor, "Color", "item color" },
            { PARAM_selectColor, "Color", "selected color" },
            { PARAM_fontColor, "Color", "font color" },
            { PARAM_fontselColor, "Color", "selected font color" },
            { PARAM_fontName, "String", "font name" },
            { PARAM_fontStyle, "Integer", "font style 0=PLAIN 1=BOLD 2=ITALIC" },
            { PARAM_fontSize, "Integer", "font size" },
            { PARAM_menuStyle, "Integer", "menu style" },
            { PARAM_menuDefault, "Integer", "menu default" },
            { PARAM_centerHoriz, "Boolean", "Q: center horizontally?" },
            { PARAM_centerVert, "Boolean", "Q: center vertcially?" },
            { PARAM_labelDefault, "String", "label default" },
            { PARAM_labelPrefix, "String", "label prefix" },
            { PARAM_labelSuffix, "String", "label suffix" },
            { PARAM_targetDefault, "String", "default target frame" },
            { PARAM_numItems, "Integer", "number of menu items" },
        };
        return info;		
    }

    // The init() method is called by the AWT when an applet is first loaded or
    // reloaded.  Override this method to perform whatever initialization your
    // applet needs, such as initializing data structures, loading images or
    // fonts, creating frame windows, setting the layout manager, or adding UI
    // components.
    //--------------------------------------------------------------------------
    public void init()
    {
        // PARAMETER SUPPORT
        //      The following code retrieves the value of each parameter
        // specified with the &lt;PARAM&gt; tag and stores it in a member
        // variable.
        //----------------------------------------------------------------------
        String param;

        // bgColor: background color
        //----------------------------------------------------------------------
        param = getParameter(PARAM_bgColor);
        if (param != null)
            try {
                m_bgColor = new Color(Integer.parseInt(param,16));
            } catch (Exception E) { } 

        // lnColor: line color
        //----------------------------------------------------------------------
        param = getParameter(PARAM_lnColor);
        if (param != null)
            try {
                m_lnColor = new Color(Integer.parseInt(param,16));
            } catch (Exception E) { } 

        // itemColor: item color
        //----------------------------------------------------------------------
        param = getParameter(PARAM_itemColor);
        if (param != null)
            try {
                m_itemColor = new Color(Integer.parseInt(param,16));
            } catch (Exception E) { } 

        // selectColor: selected color
        //----------------------------------------------------------------------
        param = getParameter(PARAM_selectColor);
        if (param != null)
            try {
                m_selectColor = new Color(Integer.parseInt(param,16));
            } catch (Exception E) { } 

        // fontColor: font color
        //----------------------------------------------------------------------
        param = getParameter(PARAM_fontColor);
        if (param != null)
            try {
                m_fontColor = new Color(Integer.parseInt(param,16));
            } catch (Exception E) { } 

        // fontselColor: selected font color
        //----------------------------------------------------------------------
        param = getParameter(PARAM_fontselColor);
        if (param != null)
            try {
                m_fontselColor = new Color(Integer.parseInt(param,16));
            } catch (Exception E) { } 

        // font stuff
        //----------------------------------------------------------------------
        param = getParameter(PARAM_fontName);
        if (param != null)
            m_fontName = param;
        param = getParameter(PARAM_fontStyle);
        if (param != null)
            try {
                m_fontStyle = Integer.parseInt(param);
            } catch (Exception E) { } 
        param = getParameter(PARAM_fontSize);
        if (param != null)
            try {
                m_fontSize = Integer.parseInt(param);
            } catch (Exception E) { } 
        fontFont = new Font(m_fontName, m_fontStyle, m_fontSize);
        fontMetrics = getFontMetrics(fontFont);

        // style: menu style
        //----------------------------------------------------------------------
        param = getParameter(PARAM_menuStyle);
        if (param != null) 
            m_menuStyle = Integer.parseInt(param);
        else
            m_menuStyle = 0;

        // style: menu default
        //----------------------------------------------------------------------
        param = getParameter(PARAM_menuDefault);
        if (param != null) 
            m_menuDefault = Integer.parseInt(param);
        else
            m_menuDefault = 0;

        // center horizontally?
        //----------------------------------------------------------------------
        param = getParameter(PARAM_centerHoriz);
        if (param != null) 
            m_centerHoriz = (Integer.parseInt(param) != 0);
        else
            m_centerHoriz = false;

        // center vertically?
        //----------------------------------------------------------------------
        param = getParameter(PARAM_centerVert);
        if (param != null) 
            m_centerVert = (Integer.parseInt(param) != 0);
        else
            m_centerVert = true;

        // label default
        //----------------------------------------------------------------------
        param = getParameter(PARAM_labelDefault);
        if (param != null)
            m_labelDefault = param;

        // label prefix
        //----------------------------------------------------------------------
        param = getParameter(PARAM_labelPrefix);
        if (param != null)
            m_labelPrefix = param;

        // label suffix
        //----------------------------------------------------------------------
        param = getParameter(PARAM_labelSuffix);
        if (param != null)
            m_labelSuffix = param;

        // default target frame
        //----------------------------------------------------------------------
        param = getParameter(PARAM_targetDefault);
        if (param != null)
            m_targetDefault = param;

        // number of items
        //----------------------------------------------------------------------
        param = getParameter(PARAM_numItems);
        if (param != null)
            try {
                m_numItems = Integer.parseInt(param);
            } catch (Exception E) { } 

        // the Items: the menu items
        //----------------------------------------------------------------------
        int x = 0; // start x
        int ix = 6; // interval x
        int px = 5; // padding x
        int py = 5; // padding y
        int yd = fontMetrics.getHeight() + py; // height
        int y = 0; // start y
        if (m_centerVert)
            y = (size().height - yd) / 2; // start y
        int yf = y + fontMetrics.getHeight(); // font y

        for (int i = 1; i &lt;= m_numItems; i++)
        {
            String i_text = getParameter("text_" + i);
            String i_url = getParameter("url_" + i);
            String i_target = getParameter("target_" + i);
            if (i_target == null)
                i_target = m_targetDefault;
            String i_label = getParameter("label_" + i);
            String i_selectColor = getParameter("selectColor_" + i);
            Color itemSelectColor = m_selectColor;
            if (i_selectColor != null)
                try {
                    itemSelectColor = new Color(Integer.parseInt(i_selectColor,16));
                } catch (Exception E) { } 
            String i_fontselColor = getParameter("fontselColor_" + i);
            Color itemFontselColor = m_fontselColor;
            if (i_fontselColor != null)
                try {
                    itemFontselColor = new Color(Integer.parseInt(i_fontselColor,16));
                } catch (Exception E) { } 

            int xd = fontMetrics.stringWidth(i_text) + (2 * px);
            items.addElement(new fjMenuItem(i_text, i_url, i_target, i_label, 
                x, y, xd, yd, x + px, yf,
                m_bgColor, m_lnColor, m_itemColor, itemSelectColor, m_fontColor, itemFontselColor, 
                fontFont, fontMetrics, m_menuStyle, this));
            x = x + xd + ix;
        }

        // center the bar horizontally
        if (m_centerHoriz) {
            int hx = (size().width + ix - x) / 2;
            for (int i = 0; i &lt; m_numItems; i++) {
                curItem = (fjMenuItem)items.elementAt(i);
                curItem.xOffset(hx);
            }
        }

        // set menu default
        if (m_menuDefault &gt; 0) {
            curItem = (fjMenuItem)items.elementAt(m_menuDefault - 1);
            curItem.select();
            itemSelected = true;
        }

        // If you use a ResourceWizard-generated "control creator" class to
        // arrange controls in your applet, you may want to call its
        // CreateControls() method from within this method. Remove the following
        // call to resize() before adding the call to CreateControls();
        // CreateControls() does its own resizing.
        //----------------------------------------------------------------------
//    	resize(320, 240);

        // TODO: Place additional initialization code here
    }

    // Place additional applet clean up code here.  destroy() is called when
    // when you applet is terminating and being unloaded.
    //-------------------------------------------------------------------------
    public void destroy()
    {
        // TODO: Place applet cleanup code here
    }

    // fjMenu Paint Handler
    //--------------------------------------------------------------------------
    public void paint(Graphics g)
    {
        // draw background
        g.setColor(m_bgColor);
        g.fillRect(0, 0, size().width, size().height);

        // draw items
        for (int i = 0; i &lt; m_numItems; i++) {
            fjMenuItem checkItem = (fjMenuItem)items.elementAt(i);
            checkItem.paint(g);
        }

        // draw label
        if (itemSelected &amp;&amp; appletActive) {
            if (curItem.label() != null)
                showStatus(m_labelPrefix + ' ' + curItem.label() + ' ' + m_labelSuffix);
        } else if (appletActive) {
            if (m_labelDefault != null)
                showStatus(m_labelDefault);
        } else
            showStatus(" ");
    }

    //      The start() method is called when the page containing the applet
    // first appears on the screen. The AppletWizard's initial implementation
    // of this method starts execution of the applet's thread.
    //--------------------------------------------------------------------------
    public void start()
    {
        // TODO: Place additional applet start code here
    }
	
    //      The stop() method is called when the page containing the applet is
    // no longer on the screen. The AppletWizard's initial implementation of
    // this method stops execution of the applet's thread.
    //--------------------------------------------------------------------------
    public void stop()
    {
        // TODO: Place additional applet stop code here
    }

    // MOUSE SUPPORT:
    //      The mouseDown() method is called if the mouse button is pressed
    // while the mouse cursor is over the applet's portion of the screen.
    //--------------------------------------------------------------------------
    public boolean mouseDown(Event evt, int x, int y)
    {
        // TODO: Place applet mouseDown code here
        if (itemSelected)
            curItem.activate();
        return true;
    }

    // MOUSE SUPPORT:
    //		The mouseUp() method is called if the mouse button is released
    // while the mouse cursor is over the applet's portion of the screen.
    //--------------------------------------------------------------------------
    public boolean mouseUp(Event evt, int x, int y)
    {   
        // TODO: Place applet mouseUp code here
        return true;
    }

    // MOUSE SUPPORT:
    //      The mouseDrag() method is called if the mouse cursor moves over the
    // applet's portion of the screen while the mouse button is being held down.
    //--------------------------------------------------------------------------
    public boolean mouseDrag(Event evt, int x, int y)
    {
        // TODO: Place applet mouseDrag code here
        return true;
    }

    // MOUSE SUPPORT:
    //		The mouseMove() method is called if the mouse cursor moves over the
    // applet's portion of the screen and the mouse button isn't being held down.
    //--------------------------------------------------------------------------
    public boolean mouseMove(Event evt, int x, int y)
    {
        // TODO: Place applet mouseMove code here
        for (int i = 0; i &lt; m_numItems; i++) {
            fjMenuItem checkItem = (fjMenuItem)items.elementAt(i);
            if (checkItem.contains(x, y)) {
                if (itemSelected) {
                    if (checkItem == curItem)
                        return true;
                    curItem.unselect();
                    curItem = checkItem;
                    curItem.select();
                } else {
                    curItem = checkItem;
                    curItem.select();
                    itemSelected = true;
                }
                paint(getGraphics());
                return true;
            }
        }

        // event point not contained in any item
        if (itemSelected) {
            curItem.unselect();
            itemSelected = false;
            paint(getGraphics());
        }

        return true;
    }

    // MOUSE SUPPORT:
    //      The mouseEnter() method is called if the mouse cursor enters the
    // applet's portion of the screen.
    //--------------------------------------------------------------------------
    public boolean mouseEnter(Event evt, int x, int y)
    {
        // TODO: Place applet mouseEnter code here
        if (m_menuDefault &gt; 0) {
            curItem = (fjMenuItem)items.elementAt(m_menuDefault - 1);
            curItem.unselect();
            itemSelected = false;
        }
        appletActive = true;
        paint(getGraphics());
        return true;
    }

    // MOUSE SUPPORT:
    //      The mouseExit() method is called if the mouse cursor leaves the
    // applet's portion of the screen.
    //--------------------------------------------------------------------------
    public boolean mouseExit(Event evt, int x, int y)
    {
        // TODO: Place applet mouseExit code here
        if (itemSelected) {
            curItem.unselect();
            itemSelected = false;
        }
        if (m_menuDefault &gt; 0) {
            curItem = (fjMenuItem)items.elementAt(m_menuDefault - 1);
            curItem.select();
            itemSelected = true;
        }
        appletActive = false;
        paint(getGraphics());
        return true;
    }

    // TODO: Place additional applet code here
}
</pre></body></html>