LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: edwin0713 on May 15, 2011, 23:46:44

Title: How to call javascript function from java by using lwjglapplet?
Post by: edwin0713 on May 15, 2011, 23:46:44
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~~
Title: Re: How to call javascript function from java by using lwjglapplet?
Post by: jediTofu on May 16, 2011, 03:09:10
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
Title: Re: How to call javascript function from java by using lwjglapplet?
Post by: edwin0713 on May 16, 2011, 03:57:00
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>