The user interface callbacks we have talked about were our first example of calling JavaFX code from JavaScript. But you can use such calls not only for preset API methods but also for any logic, for example, as a reaction to a button press.
Let's see how it works.
First of all, you need to get access to the JavaScript window object as we already did in the previous section:
JSObject window = (JSObject) webEngine.executeScript("window");
Now you can inject a random object into the window:
window.setMember("app", this);
Given that we call this code in the start() method, we are providing a link to the JavaFX application. ...