// 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 
// rewritten in Java Swing Spring 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 35 and 36. Thanks.

   import java.net.*;
   import java.awt.*;
   import java.applet.*;
   import java.awt.event.*;
   import javax.swing.*;
	
    public class JDemoMenu extends JApplet implements MouseListener 
   {
      String[] names;   // array of strings	
      String[] url;
      int i,MAX_NUMBER_URLs=12; // max 12 buttons
      int max; // the number passed to the applet
      private JButton[] places = new JButton[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 JButton(names[i]);
        // place the buttons on the screen
         Container con = getContentPane();      
         con.setLayout(new GridLayout(max, 1,3,3));
       
         for(i = 0 ; i < max; ++i){
            con.add(places[i]);
            places[i].setFont(buttonFont);
            places[i].setBackground(Color.white);
            places[i].addMouseListener(this);   	
         }
      }
       public void mousePressed(MouseEvent e)
      {
      }
   
       public void mouseClicked(MouseEvent e)
      {
         URL target=null;
         try{ // find the url and 
            for(i = 0 ; i < max; ++i)
               if(e.getSource()==places[i])	{
                  target = new URL(url[i]); 
                  break;
               }
         }
             catch(MalformedURLException x)
            {
            }
         AppletContext browser = getAppletContext();
         browser.showDocument(target);
      }
   
       public void mouseEntered(MouseEvent e)
      {
         for(i = 0 ; i < max; ++i)
            if(e.getSource()==places[i]){
               places[i].setBackground(Color.gray);
               places[i].setForeground(Color.white);
            }
      }
   
       public void mouseExited(MouseEvent e)
      {
         for(i = 0 ; i < max; ++i)
            if(e.getSource()==places[i]){
               places[i].setBackground(Color.white);
               places[i].setForeground(Color.black);
            }
      
      }
   
       public void mouseReleased(MouseEvent e)
      {
      }
   }