Academic Java    Java Tutorial  >  Applets  >  go to URL

go to URL Example

If this applet was running in a browser it would visit another URL and replace the current page of the browser by the one visited.
// goto URL applet example using the showDocument() method
import java.net.*;
import javax.swing.*;

class GotoURLExample extends JApplet {


   void visit(String urlString) {

      try {
         URL url = new URL(getDocumentBase(), urlString);
         getAppletContext().showDocument(url);
      }
      catch(MalformedURLException e) {}

   }

   @Override public void start() {

      visit("http://academicjava.com");

   }

}