Sounds to me you want to call a Java (or groovy!) function found within the Applet from the outside world using JavaScript, right?
In order for this to work:
You must have livescript enabled and the applet's jar must be signed.
The next step is to define an entry point in the applet subclass that knows how to handle the call you want to make.
This is where it gets tricky because the default applet class is
griffon.swing.SwingApplet
so you must create your own subclass ofgriffon.swing.SwingApplet
and use it as the main entry point.Your subclass will be the one that defines the method (or methods) callable from the JavaScript side. This should be something along the lines of:
import griffon.swing.SwingApplet; public class MySwingApplet extends SwingApplet { // match superclass constructors public CalculatorApplet(String[] args) { super(args); } public Object myAppletMethod(String[] args) { // args come form the JS world // do whatever is necessary here } }
To tell Griffon to use our custom applet subclass instead of the default, simply create a file named
griffon-app/scripts/_Events.groovy
and place the following inside:eventPackageAppStart = { griffonAppletClass = 'calculator.CalculatorApplet' }
Finally, grab hold of the applet object from javascript and invoke
myAppletMethod()
with any values you see fit:<script> function talkToApplet() { var r = document.applets.myAppletId.myAppletMethod("arg1", "arg2"); alert(r); } </script>
A more detailed example can be found on my blog.