3

I am trying to call JavaScript functions from a JApplet. I've searched through tutorials and they say that I need to import and use netscape.javascript.* from my \jre\lib\plugin.jar

I did import netscape.javascript.* and I'm using DrJava, and it kept saying it cannot find the getWindow method.

This is the error it gives me:
(MinesweeperApplet extends JApplet)

Error: cannot find symbol  
    symbol:   method getWindow(MinesweeperApplet)  
    location: class netscape.javascript.JSObject

This is the piece of code inside the MinesweeperApplet class where I am trying to get the JSObject:

public void start(){                
    // add stuff    
    JSObject window = JSObject.getWindow(this);    
    Container cp = getContentPane();
    ...

I appreciate any help. Thanks!

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
darolandi
  • 71
  • 10
  • *"I'm using DrJava"* ..to run the applet? How are you testing it? AFAIU no (development) environment short of a 'browser' will have the functionality of the `JSObject`. – Andrew Thompson May 21 '13 at 01:06
  • I meant I'm using DrJava (as opposed to NetBeans or Eclipse) to write and compile the Java source code. And the error message I gave above is given by DrJava's compiler. The Java application by itself works fine, I even tested in browser. But when I tried to add Java-to-Javascript communication, this problem came. – darolandi May 21 '13 at 01:38
  • *"to write and compile"* Right. Silly me. :P Sorry, don't know much about DrJAva and setting the Compile time class-path in it. Does it run Ant build files? – Andrew Thompson May 21 '13 at 06:59

1 Answers1

3

I have found the "solution."

Previously I was using JDK 7. Then I downloaded and tried JDK 6 (update 45) and it could compile fine. And from that point on, the Java-to-Javascript communication works.

darolandi
  • 71
  • 10