A Tour Guide Applet for Web Sites

Most web sites have a navigation problem. You put up a bunch of pages, but new visitors do not know where to start or what order to read things in. They click around randomly, miss the best content, and leave. What if you could give them a guided tour?

I wrote a Java applet called TourGuide that does this. Think of it as a precursor to a smart agent that works as a tour guide to a site. JavaScript opens the applet's page in a smaller popup window, where the applet presents a list of links in the order you have chosen. The visitor double-clicks a stop to see a page you think is most worth visiting.

The key design choice is that the tour data lives in a plain text file, not in the Java code. The applet reads pairs of lines: a label for a stop, followed by its web address without the http:// prefix, which the code supplies. When you want to change the tour, you edit the text file. You do not have to recompile the applet. This means someone who does not know Java can maintain the tour just by editing a simple text file.

The applet itself is embedded in a page with an <APPLET> tag. When a visitor loads that page, the applet starts, reads the data file from the server, and fills the list of stops. Double-clicking a stop opens its page in the browser window named by the frame_name parameter. The example uses display; the browser can reuse that window or open it if it does not exist. The applet stays in its smaller window, acting as a persistent guide.

The popup window approach keeps the tour controls visible while the visitor reads each page. It is like having a small control panel that floats alongside the browser. The visitor can close it at any time if they want to explore on their own.

For a newspaper web site, a tour can introduce new visitors to the different sections, highlight the features of the site, show them how to find classified ads, or walk them through the opinion pages. For a corporate site, it can show your products in a logical order. For a personal site, it can present your portfolio the way you would present it in person.

Java applets are well suited to this kind of thing. The applet runs in a Java-capable browser, can ask the browser to display a page in another window, and can make HTTP requests back to its server to load the data file. Java-enabled versions of Netscape Navigator 2.0 support applets, and other browsers are adding support.

The separation between the applet code and the tour data is the part I think matters most. A tour guide is only useful if you can update it easily. Putting the link data in an external file means the person who knows the content can maintain the tour without involving a programmer. That is how tools should work: the technology stays out of the way and lets the content people do their job.

The applet is freely available for anyone to use on their site. The source, sample tour data, popup page, and compiled applet are available on my web site. Save the bytecode as TourGuide.class and use that name in the <APPLET> tag; set the codebase attribute and give the links_file parameter the absolute URL of your data file.

Here is the full source code:

/**

TourGuide.java

An Applet by Rajiv Pant (Betul)

A web site navigator, also
a Tour Guide for your visit to a web site or a group of web sites.

Parameters can be set from calling html page so that other sites
may easily use this applet.

Aim of applet / Future Additions:

* To be fully customizable.
* Use full multimedia introductions to sites. (Of course, users can
turn off sound :-)

* If a page has special instructions for its introduction (which may
either be stored in the page itself on in the links file specified
as a parameter to the applet, the applet can do special things including:

   ** Open another window to display an introduction page.
   ** Parse the page and display it in parts explaing things.

 @version 1.00 1996/Mar/14
 @author Rajiv Pant (Betul)

*/

import java.awt.*;
import java.applet.*;
import java.net.*;
import java.io.*;
import java.util.* ; // for Hashtable

public class TourGuide extends Applet
{  public void init()
   {

      System.out.print ("\n\nHello.\n\n" ) ;

      setBackground (Color.white) ;

      boolean read = readLinksFile() ;

      setLayout(new BorderLayout());
      add("Center", links);

   }

   public boolean action(Event evt, Object arg)
   {  if (evt.target == links)
      {  try
         {  AppletContext context = getAppletContext();
            URL u = new URL ( (String) ( its_link.get ( (String)arg ) )  )  ;
            context.showDocument(u, getParameter("frame_name")) ;
         } catch(Exception e)
         {  showStatus("Error " + e);
         }
      }
      else return super.action(evt, arg);
      return true;
   }

   private List links = new List(10, false);
   Hashtable its_link = new Hashtable() ;

private boolean readLinksFile()
{

  System.out.print (
"I am going to read in the list of links now. \n\n"
) ;

  URL FileURL = null ;

  try
  {
     FileURL = new URL ( getParameter("links_file") ) ;
  }
  catch (MalformedURLException e)
  {
     showStatus("Error " + e) ;
  }


  try
  {
     InputStream in = FileURL.openStream() ;
     DataInputStream din = new DataInputStream (in) ;

     String description = "" ;
     String link        = "" ;

     while (  ( description = din.readLine() ) != null )
     {
        if ( (link = din.readLine() ) != null )
        {
          link = "http://" + link ;
          its_link.put (description, link) ;
          links.addItem (description) ;
          System.out.println ("Description: " + description) ;
          System.out.println ("Link:        " + link + "\n") ;
        }
     }

  }
  catch (IOException e)
  {
     showStatus("Error " + e) ;
  }

  return true ;
} // readLinksFile

}