Skip navigation links
NASA World Wind

Package gov.nasa.worldwindx.examples.applet

Examples of a displaying a World Wind globe in a Java Applet.

See: Description

Package gov.nasa.worldwindx.examples.applet Description

Examples of a displaying a World Wind globe in a Java Applet. Instructions for deploying Applets and live Applet examples are available at http://goworldwind.org. Important links for Applets on goworldwind.org:

The WWJApplet and WWJAppletMinimal classes in this package demonstate how to display a WorldWindow inside a Java Applet, and how to communicate between the Applet and the browser. The documents WWJApplet.html and WWJApplet.jnlp in the demos folder demonstrate how to embed a World Wind Applet in a web page.

Applet Parameters

Applet parameters can be specified in HTML via the applet or object tag using the param field.

    <param name="key" value="value">

The Applet can then retrieve this parameter using Applet's getParameter method.

    String value = getParameter("key");

Java-to-Javascript Communication

This section provides a basic overview of communication between a Java Applet and the browser's Javascript runtime, referred to as LiveConnect. For more information see Oracle's Java Applet tutorial at
http://docs.oracle.com/javase/tutorial/deployment/applet/index.html

Enable Java-to-Javascript Communication

Add the id and mayscript attributes to the applet tag to enable Java-to-Javascript communication. The id attribute provides a DOM Id that Javascript uses to identify the Applet. The mayscript attribute enables the browser to call Javascript functions from Java using the JSObject class.
    <script src="http://www.java.com/js/deployJava.js"></script>
    <script>
        var attributes = {id:'appletId', mayscript:'true', ...};
        var parameters = ...;
        deployJava.runApplet(attributes, parameters, '1.6'); // runApplet automatically looks for JRE 1.6+
    </script>

Call Java Methods from Javascript

    // Provide a common method for accessing the World Wind applet.
    var theApplet = null;
    function getApplet()
    {
        if (theApplet == null)
        {
            theApplet = document.getElementById('appletId'); // id attribute specified in the applet tag.
        }

        return theApplet;
    }

    // Call the Java Applet method doSomething() from Javascript.
    getApplet().doSomething();

Call Javascript Functions from Java

    import netscape.javascript.JSObject;

    // Call the Javascript doSomethingJS method from the Java Applet.
    JSObject win = JSObject.getWindow(this);
    win.call("doSomethingJS", null);

    // Evaluate and execute Javascript code as a string.
    win.eval("alert('An alert message')");
Skip navigation links
NASA World Wind