You are here:   HomeJava ProgrammingAWT and AppletsWhat is Repainting method in java?
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();

                         }

     }

}



What's New and Popular