CS 596 Java Programming Fall Semester, 1998 Show URL Applet |
||
---|---|---|
San Diego State University -- This page last updated 16-Dec-98 |
<CENTER> <APPLET ARCHIVE="AppletClasses.jar" CODE="ShowDocumentApplet.class" WIDTH=150 HEIGHT=50 HSPACE=5 VSPACE=10> Your browser does not support Java applets, so you can not see this applet operate. </APPLET> </CENTER>
import java.applet.*; import java.net.URL; import java.net.MalformedURLException; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.Button; import java.awt.Graphics; import java.awt.Dimension; public class ShowDocumentApplet extends Applet { Button display = new Button( "Go to www.eli" ); public void init( ) { add( display ); display.addActionListener( new ButtonListener() ); } class ButtonListener implements ActionListener { public void actionPerformed( ActionEvent event ) { try { URL wwwEli = new URL( "http://www.eli.sdsu.edu" ); AppletContext myContext = getAppletContext(); myContext.showDocument( wwwEli, "_blank"); } catch (MalformedURLException canNotHappen ) { //hard coded a valid URL } } } }