FileDocCategorySizeDatePackage
Browser2.javaAPI DocExample1732Mon Oct 16 19:44:08 BST 2000None

Browser2

public class Browser2 extends JFrame implements HyperlinkListener

Fields Summary
private JEditorPane
html
private URL
url
Constructors Summary
public Browser2(String site)

	setSize( 350, 450 );
		setTitle( "Scrolling Browser" );
		addWindowListener( new WindowAdapter() {
			public void windowClosing( WindowEvent e )
			{	System.exit( 0 );
			}
		});

		try
		{	url = new URL( site );
		}
		catch( MalformedURLException e )
		{	System.out.println( "Invalid URL specified" );
			System.exit( 0 );
		}
		try
		{	html = new JEditorPane( url );
		}
		catch( IOException e )
		{	System.out.println( "Can't load url: " + url );
			System.exit( 0 );
		}
		
		JScrollPane scroller = new JScrollPane();
		JViewport viewport = scroller.getViewport();
		viewport.add( html );
		
		getContentPane().add( scroller );
		html.setEditable( false ); // to allow links to be activated
		html.addHyperlinkListener( this );
		
		setVisible( true );
	
Methods Summary
public voidhyperlinkUpdate(javax.swing.event.HyperlinkEvent e)

	if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
		{	try
			{  html.setPage( e.getURL() );
			}
			catch( IOException ioe )
			{	System.out.println( "Can't load url: " + url );
				System.exit( 0 );
			}
		}
	
public static voidmain(java.lang.String[] args)

	new Browser2( args[0] );