How to call javascript function from java by using lwjglapplet?

Started by edwin0713, May 15, 2011, 23:46:44

Previous topic - Next topic

edwin0713

In my main file.
public class MainFile extends LwjglApplet
{
   scoreManager = new ScoreManager();
}

In my scoreManager
public class ScoreManager extends JApplet
{   
   JSObject window = JSObject.getWindow(this);
      
    public void SubmitScore(){
        Object array[];
        array = new Object[2];

        array[0] = currentGameMode;
        array[1] = GridSize;

        window.call("submitScore", array);
    }
}

error:

Exception in thread "main" netscape.javascript.JSException
   at netscape.javascript.JSObject.getWindow(Unknown Source)
   at com.liquidrockgames.wordzen.ScoreManager.<init>(ScoreManager.java:9)
   at com.liquidrockgames.wordzen.MainFile.main(WordZenApplet.java:52)
Caused by: java.lang.NullPointerException
   at java.applet.Applet.getParameter(Unknown Source)
   ... 3 more

Anyone can help me please~~

jediTofu

Instead of initializing where you define the variable, try it in JApplet's init method:

...
JSObject window;
public void init() {
  window = JSObject.getWindow(this);
}
...

http://java.sun.com/products/plugin/1.3/docs/jsobject.html
cool story, bro

edwin0713

After click the submit score, the application in browser become blank
i run my program by browser instead of compiler.
HTML
<script>
        function submitScore(gameMode, highScore)
        {
        
        }
  </script>