You can save the following code as HelloWorldSimple.js and make executable using chmod +x HelloWorldSimple.js and then run using ./HelloWorldSimple.js:
Code: Select all
#!/usr/lib/jvm/jdk-8-oracle-arm-vfp-hflt/bin/jjs -fx
var Button = javafx.scene.control.Button;
var StackPane = javafx.scene.layout.StackPane;
var Scene = javafx.scene.Scene;
$STAGE.title = "Hello World!";
var button = new Button();
button.text = "Say 'hello, world'";
button.onAction = function() { print("hello, world"); quit(); };
var root = new StackPane();
root.children.add(button);
$STAGE.scene = new Scene(root, 300, 250);
$STAGE.show();You can save the following code as HelloWorld.js and make executable using chmod +x HelloWorld.js and then run using ./HelloWorld.js:
Code: Select all
#!/usr/lib/jvm/jdk-8-oracle-arm-vfp-hflt/bin/jjs -fx
var Group = javafx.scene.Group;
var Scene = javafx.scene.Scene;
var Text = javafx.scene.text.Text;
var Platform = Java.type("javafx.application.Platform");
var Timer = Java.type("java.util.Timer");
$STAGE.scene = new Scene(new Group(new Text(25, 25, "Hello World!")));
$STAGE.title = "Hello World!";
$STAGE.show();
setTimeout(function() { print("Quitting..."); quit(); }, 5000);
function setTimeout(func, milliseconds) {
var timer = new Timer("setTimeout", true);
timer.schedule(function() Platform.runLater(func), milliseconds);
return timer;
}One solution is to use one Raspberry Pi as JavaFX display and log in from another computer (which could be another Raspberry Pi) using SSH. Still, it's rather good one can use JavaFX from JavaScript. I use Raspberry Pi 2 B.
I made an AWT-version of HelloWorldSimple.js called AWTHelloWorldSimple.js and that runs in a window:
Code: Select all
#!/usr/lib/jvm/jdk-8-oracle-arm-vfp-hflt/bin/jjs -strict=true -fv
//#!/usr/bin/env rhino
var Button = java.awt.Button;
var Frame = java.awt.Frame;
var Dimension = java.awt.Dimension;
frame = new Frame("Hello World!");
button = new Button("Say 'hello, world'");
button.addActionListener(function() { print("hello, world"); quit(); })
frame.add(button);
frame.setSize(new Dimension(200,100));
frame.show();
for(;;)
java.lang.Thread.sleep(1000);