by Dinesh Thakur Category: AWT and Applets

Java allows the applet to transfer the control to another URL by using the showDocument () Method defined in the AppletContext interface. For this, first of all, it is needed to obtain the Context of the currently executing applet by calling the getAppletContext () method defined by the Applet. Once the context of the applet is obtained with in an applet, another document can be brought into view by calling showDocument () method.

There are two showDocument () methods which are as follows:

showDocument(URL url)

showDocument(URL url,string lac)

where,

url is the URL from where the document is to be brought into view.

loc is the location within the browser window where the specified document is to be displayed.

Example An applet code to demonstrate the use of AppletContext and showDocument ().

import java.applet.Applet;

import java.applet.AppletContext;

import java.net.*;

/*

<applet code="LoadHTMLFileSample" width="700" height="500"></applet>

*/

public class LoadHTMLFileSample extends Applet

{

    public void start()

    {

          AppletContext context= getAppletContext();

          //get AppletContext

          URL codeBase = getCodeBase(); //get Applet code base

          try{

                 URL url = new URL(codeBase + "Test.html");

                 context.showDocument(url,"_blank");

                 repaint();

               }catch(MalformedURLException mfe) {

                         mfe.printStackTrace();

                         }

     }

}



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Search Content





Popular Article