A very simple way to call Javascript method from Java Applet.
Java Applet Side
import java.applet.*; import java.net.*; public class InJava4 extends Applet{ private void callJs(String s, Object aobj[]) { try { Object aobj[] = new Object[3]; aobj[0] = "param1"; aobj[1] = "param2"; aobj[2] = "param3"; JSObject.getWindow(this).call("some_javascript_function", aobj); } catch (JSException jsexception) { System.out.println((new StringBuilder()).append("JavaScript exception delivering ").append(s).toString()); } } }
HTML Side
<HTML> <HEAD> <SCRIPT src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type="text/javascript"></SCRIPT> <SCRIPT type="text/javascript"> function some_javascript_function() { var args=$.makeArray(arguments); doAlert(args.shift()); doAlert(args.shift()); doAlert(args.shift()); } </SCRIPT> </HEAD> <BODY> <APPLET CODE="InJava4.class" NAME="myApplet" MAYSCRIPT HEIGHT=10 WIDTH=10></APPLET> </BODY> </HTML>
Reference:
http://www.rgagnon.com/javadetails/java-0172.html
http://download.oracle.com/javase/6/docs/technotes/guides/plugin/developer_guide/java_js.html
From JavaScript to Java
http://download.oracle.com/javase/1.4.2/docs/guide/plugin/developer_guide/js_java.html
No comments:
Post a Comment