This page demonstrates the use of the showDocument method. No frills, just code.
Here's the applet:
And here's the code:
(Get it in a separate file here)
import java.awt.Button;
import java.awt.Event;
import java.net.*;
public class SDTest extends java.applet.Applet {
URL testurl;
URL testurl2;
Button urlbutton;
Button urlbutton2;
Button urlbutton3;
public void init() {
resize(100, 200);
try {
testurl = new URL("http://www.io.com/~maus/JavaNetworkingFAQ.html");
testurl2 = new URL("http://search.yahoo.com/bin/search?p=java");
}
catch (MalformedURLException e) {
}
urlbutton = new Button("Get the FAQ");
urlbutton2 = new Button("FAQ (new Page)");
urlbutton3 = new Button("Search Yahoo");
add(urlbutton);
add(urlbutton2);
add(urlbutton3);
}
public boolean action(Event evt, Object obj) {
if (evt.target == urlbutton) {
getAppletContext().showDocument(testurl);
}
else if (evt.target == urlbutton2) {
getAppletContext().showDocument(testurl, "_blank");
}
else if (evt.target == urlbutton3) {
getAppletContext().showDocument(testurl2);
}
else {
return super.action(evt, obj);
}
return true;
}
}
Back to my Java page.
Back to my homepage.
More questions? Try looking at my FAQ.