Tuesday, June 19, 2007

How can you display a particular web page from an applet?

The following code snippet shows you how to achieve that using showPage method is capable of displaying any URL passed to it.

import java.net.*;
import java.awt.*;
import java.applet.*;

public class TestApplet extends Applet
{
// Applet code goes here

// Show a page
public void showPage ( String showPage)
{
URL url = null;

// Create a URL object
try
{
url = new URL ( showPage );
}
catch (MalformedURLException e)
{
// Invalid URL
}

// Show URL
if (url != null)
{
getAppletContext().showDocument (url);
}

}
}

0 comments :

 

Disclaimer
Interview Questions On Java,Java EE Copyright © 2016. Reads: best tracker