Making the Browser Visit a URL - Java Network

Java examples for Network:URL

Description

Making the Browser Visit a URL

Demo Code


import java.applet.Applet;
import java.awt.Graphics;
import java.net.MalformedURLException;
import java.net.URL;

class BasicApplet extends Applet {
  // This method is called once by the browser when it starts the applet.
  public void init() {
    try {/* w  ww.  j a  v a2s .  c o m*/
      URL url = new URL(getDocumentBase(), "http://hostname.com/page.html");
      getAppletContext().showDocument(url);
    } catch (MalformedURLException e) {
    }
  }

  // This method is called whenever the page containing this applet is made
  // visible.
  public void start() {
  }

  // This method is called whenever the page containing this applet is not
  // visible.
  public void stop() {
  }

  // This method is called once when the browser destroys this applet.
  public void destroy() {
  }

  // This method is called whenever this applet needs to repaint itself.
  public void paint(Graphics g) {
  }
}

Related Tutorials