JSObject.getWindow (this) returns null

I managed (after a lot of struggle) to load my applet into my Firefox browser, but in the Java code for my applet, JSObject.getWindow (this) returns null for some reason I cannot figure out.

Here is my Java code for the applet:

import java.applet.*;
import javax.swing.*;
import netscape.javascript.*;
import java.net.*;
import java.io.*;
import java.awt.*;

public class JavaSocketBridge extends JApplet {

    // Instance variables
    JSObject browser = null;        // The browser
    Socket socket = null;           // The current socket
    PrintWriter out = null;         // Output
    Listener listener = null;       // Listens for input
    boolean running = false;        // Am I still running?
    String address = null;          // Where you will connect to
    int port = -1;                  // Port
    boolean connectionDone = false; // Thread synchronization
    public String message = "";

    // Initialize
    public void init(){
        try
        {
            browser = JSObject.getWindow(this); //see bottom of code for comment
        }
        catch(Exception e)
        {
            message += "EXCEPTION: " + e.getMessage() + "     THIS: " + this;
        }
    }

    // Stop and destroy
    public void stop(){
        running = false;
        disconnect();
    }
    public void destroy(){
        running = false;
        disconnect();
    }

    public void start(){
        //other code here
    }
}

      

I tried to move the line browser = JSObject.getWindow(this);

to the beginning of the method start()

as suggested here , but I still run out of luck. And the text contained in the variable message

:

Message: EXCEPTION: null THIS is: JavaSocketBridge [panel50,0,0,0x0, invalid, layout = java.awt.BorderLayout, rootPane = javax.swing.JRootPane [, 0,0,0x0, invalid, layout = javax.swing. JRootPane $ RootLayout, alignmentX = 0,0, alignmentY = 0,0, border =, e, flags = 16777673, MaximumSize =, = MinimumSize, PreferredSize =], rootPaneCheckingEnabled = true]

Here is my PHP file:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta charset="utf-8">
        <script type="text/javascript" src="JavaSocketBridge/java_socket_bridge.js"></script>
    </head>
    <body>
        <applet id="JavaSocketBridge" code="HelloWorldApplet.class" archive="./JavaSocketBridge/JavaSocketBridge.jar" height="200" width="2000"></applet>;
        <?php
            echo "  <script>
                        console.log('Applet is connected: ' + socket_connect('".$_SESSION['ip']."', '".$_SESSION['port']."'));
                        console.log('Flag Status: ' + is_ready());
                    </script>";
        ?>
    </body>
</html>

      

+3


source to share





All Articles