SDSU CS 596 Java Programming
Fall Semester, 1998
Show URL Applet
To Applet Index
San Diego State University -- This page last updated 16-Dec-98

Description

This applet shows how to have a browser display a web page in a new window.

Applet

Your browser does not support Java applets, so you can not see this applet operate.

Applet Tag

<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>

Applet Source Code

ShowDocumentApplet.java

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
        }
      }
    }
  }


Visitors since 16-Dec-98