I have a Java applet that has an int array. I want to copy this array over to a JavaScript array. Simply calling a Java function from JavaScript that returns this array results in null exception and accessing the array element by element from JavaScript leads to browser crashes. What is the correct way to handle this? Perhaps JSObject?
2 Answers
Try this:
<applet code="Applet.class" name="Applet" />
<script>var f = document.Applet.foobar();</script>
And
class Applet extends java.applet.Applet {
public void init() {}
public int[] foobar(){
return new int[]{1,2,3};
}
}
-
Huh, I guess that it worked now. Didn't work when I tried the same thing earlier. Thanks!Aravind– Aravind07/24/2013 20:18:26Commented Jul 24, 2013 at 20:18
-
Hm, it won't work if the Browser asks for Applet-Permission first. Usually programmers write a hello-callback-function.Grim– Grim07/25/2013 10:33:49Commented Jul 25, 2013 at 10:33
You could use netscape JSObject to interact with JavaScript from Java Applet. Have a look at the below tutorial. It might be useful for you.
-
Thanks, but simply calling a function that returns the int array turned out to be easier.Aravind– Aravind07/24/2013 20:19:05Commented Jul 24, 2013 at 20:19
-
Yes. it's simpler indeed :)Avinash K.P– Avinash K.P07/25/2013 05:56:59Commented Jul 25, 2013 at 5:56
applet
tagint
).