// SiteSelector.java
// Uses a button to load a document from a URL
import java.awt.*;
import java.applet.Applet;
import java.net.*;

public class SiteSelector extends Applet {
	Site siteList[ ];  // array of sites

	public void init( ) {
		siteList = new Site[ 3 ];
		siteList[ 0 ] = new Site( " Java Home ", "http://www.javasoft.com/index.html" );
		siteList[ 1 ] = new Site( "Calendar", "http://www.lehigh.edu/~sgb2/middle.html" );
		siteList[ 2 ] = new Site( "Audi", "http://www.audi.com/index.html" );

		for ( int i = 0; i < siteList.length; i++ )
			add( new Button( siteList[ i ].getTitle( ) ) );
	}

	public boolean action ( Event e, Object arg ) {
		if ( e.target instanceof Button ) {
			String title;
			URL location;

			for ( int i = 0; i < siteList.length; i++ ) {
				title = siteList[ i ].getTitle( );
				location = siteList[ i ].getLocation( );

				if ( title.equals( arg.toString( ) ) ) {
					gotoSite( location );
					return true;  // event handled
				}
			}
		}

		return false;  // event not handled yet
	}

	public void gotoSite( URL loc ) {
		//  this must be executed in a browser
		getAppletContext( ).showDocument( loc );
	}
}