1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
/* Load New HTML File Using Applet Context Example This java example shows how load a new file in a browser using showDocument() method of AppletContext. */ import java.applet.Applet; import java.applet.AppletContext; import java.net.MalformedURLException; import java.net.URL; /* <applet code="LoadNewHTMLFileExample" width=200 height=200> </applet> */ public class LoadNewHTMLFileExample extends Applet{ public void start(){ //get code base of an Applet using getCodeBase() method URL codeBase = getCodeBase(); //get AppletContext using getAppletContext() method AppletContext context = getAppletContext(); /* * To load a new HTML file in a browser use * void showDocument(URL url) * method of AppletContext class. * * PLEASE NOTE that the new HTML document must be in the * same directory. */ try{ URL url = new URL(codeBase + "AppletContextExample.html"); context.showDocument(url); }catch(MalformedURLException me){ //do nothing } } } |
Add Comment