// This applet will take params to decide on
// the urls to be used, how many buttons and the
// font size and face.
//
// This applet is a class demo and is presented as-is.
//
// By John Sklar, December, 2000 with great respect to
// color mouseover added May, 2003
// goURL.java by Michael S. Shipp (mkshp@ionet.net) for the
// application of the URL and appletContext methods. (lines 49-57) and
// his clever use of parm names in lines 31 and 32. Thanks.
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
public class DemoMenu extends Applet implements MouseListener
{
String[] names; // array of strings
String[] url;
int i,MAX_NUMBER_URLs=100; // max 100 buttons
int max; // the number passed to the applet
private Button[] places = new Button[MAX_NUMBER_URLs];// an array of buttons
public void init()
{
Font buttonFont = new Font((getParameter("fontface")), Font.BOLD, Integer.parseInt(getParameter("fontsize")));
names = new String[MAX_NUMBER_URLs];
url = new String[MAX_NUMBER_URLs];
max = Integer.parseInt(getParameter("howmany"));
for(i = 0; i < max; i++)
{
names[i]=getParameter("name" + i);
url[i]=getParameter("url" + i);
}
// make the buttons
for(i = 0 ; i < max; ++i)
places[i] = new Button(names[i]);
setLayout(new GridLayout(max, 1,3,3));
// place the buttons on the scre
for(i = 0 ; i < max; ++i){
add(places[i]);
places[i].setFont(buttonFont);
places[i].setBackground(Color.lightGray);
places[i].setForeground(Color.black);
places[i].addMouseListener(this);
}
// this is for appletviewer only.
setSize(250,200);
}
public void mousePressed(MouseEvent e)
{}
public void mouseClicked(MouseEvent e)
{
URL target=null;
getToolkit().beep();
try{ // find the url and
for(i = 0 ; i < max; ++i)
if(e.getSource()==places[i])
{
target = new URL(url[i]);
break;
} // get the page
getAppletContext().showDocument(target);
}
catch(MalformedURLException xe)
{
}
}
public void mouseEntered(MouseEvent e)
{
for(i = 0 ; i < max; ++i)
if(e.getSource()==places[i])
{
{
places[i].setBackground(Color.white);
places[i].setForeground(Color.red);
}
}
}
public void mouseExited(MouseEvent e)
{
for(i = 0 ; i < max; ++i)
if(e.getSource()==places[i])
{
places[i].setBackground(Color.lightGray);
places[i].setForeground(Color.black);
}
}
public void mouseReleased(MouseEvent e) { }
}