Platinum Partner
java

Calling JavaFX From Java?

While experimenting with JavaFX, remember that Java is never far away.

In this case, let's call out to Jim Weaver's JavaFX Calculator demo:

Here we go, here's all that's needed, via the Scripting API, which is included in the JavaFX SDK:

package calc;

import java.io.InputStreamReader;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

public class CalculatorLauncher {

public static void main(String[] args) {
try {
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByExtension("fx");
InputStreamReader reader = new InputStreamReader(CalculatorLauncher.class.getResourceAsStream("Calculator.fx"));
engine.eval(reader);
} catch (ScriptException ex) {
}
}

}
And so, here's my whole application, calling Jim Weaver's Calculator demo:

Nice. Even better would be to be able to embed that JavaFX Stage (or a panel-like part thereof?) into a JFrame. Then one would have the best of both worlds: the graphic "oomph" of JavaFX, together with the daily low level grunt work of Java. That, I believe (and hope), is the promise of JavaFX for Java developers (and Groovy developers), as opposed to designers and similar graphic artists, who seem to be the primary target of JavaFX.

{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}