<p>Is it possible to pass a function/callback from javascript to a java applet?</p>

<p>For example i have an applet with a button that when pressed it will call the passed js callback</p>

<pre><code>function onCommand() {
  alert('Button pressed from applet');
}
applet.onCommand(onCommand);
</code></pre>

You can use
JSObject
to call back into javascript from Java.
From that page:
```
```
import netscape.javascript.*;
import java.applet.*;
import java.awt.*;
class MyApplet extends Applet {
     public void init() {
         JSObject win = JSObject.getWindow(this);
         JSObject doc = (JSObject) win.getMember("document");
         JSObject loc = (JSObject) doc.getMember("location");

         String s = (String) loc.getMember("href");  // document.location.href
         win.call("f", null);                      // Call f() in HTML page
     }
}
```
```