// URLSelector.java
// Bare bones model for connecting to a web page
import java.awt.*;
import java.applet.Applet;
import java.net.*;

public class URLSelector extends Applet {
	private Label l;
	private Button b;

	private URL location;

	public void init( ) {
		l = new Label( "Go to a web page" );
		b = new Button( "GO" );
		add( l );
		add( b );

		try {
			location = new URL( "http://www.javasoft.com/index.html" );
		}
		catch ( MalformedURLException e ) {
			System.err.println( "Invalid URL" );
		}
	}

	public boolean action ( Event e, Object arg ) {
		if ( e.target instanceof Button ) {
			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 );
	}
}