// The ROMenu class // Creates a vertical URL menu that uses RollOver objects import java.awt.*; import java.applet.*; import java.awt.event.*; import java.net.*; public class ROMenu extends Applet implements MouseListener { RollOver[] choices; String[] urls; public void init() { Color Bg1 = getParameter("BG1") == null? null : new Color(Integer.parseInt(getParameter("BG1"), 16)); Color Fg1 = getParameter("FG1") == null? null : new Color(Integer.parseInt(getParameter("FG1"), 16)); Color Bg2 = getParameter("BG2") == null? null : new Color(Integer.parseInt(getParameter("BG2"), 16)); Color Fg2 = getParameter("FG2") == null? null : new Color(Integer.parseInt(getParameter("FG2"), 16)); // Count the number of items on the menu int items = 1; while ((getParameter("CAPTION"+items) != null) && (getParameter("URL"+items) != null)) items++; items --; // If no items on the menu, then leave if (items == 0) { add(new Label("No menu items")); return; } // Allocate the arrays choices = new RollOver[items]; urls = new String[items]; // Initialize the arrays setLayout(new GridLayout(items, 1)); setFont(new Font("Helvetica", Font.BOLD, 24)); for (int i = 0; i < items; i++ ) { choices[i] = new RollOver( getParameter("CAPTION"+(i+1)), Label.CENTER, "", Fg1, Bg1, Fg2, Bg2); add(choices[i]); choices[i].addMouseListener(this); urls[i] = getParameter("URL"+(i+1)); } } public void mouseClicked(MouseEvent e) { Label clicked = (Label) e.getSource(); for (int i = 0; i < choices.length; i++) if (choices[i] == clicked) { try { URL u = null; if (urls[i].startsWith("http")) u = new URL(urls[i]); else u = new URL(getCodeBase(), urls[i]); getAppletContext().showDocument(u, "_blank"); } catch (MalformedURLException ie) { showStatus("Sorry, don't recognize: " + urls[i]); } } } // ------------------------------------------------------- // Dummy methods for MouseListener interface // ------------------------------------------------------- public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } }