Java Reference
In-Depth Information
@Override
public void init() {
msg = new Text("Hello JavaFX from Nashorn!");
msg.setFont(Font.font("Helvetica", 18));
sp = new StackPane(msg);
}
@Override
public void start(Stage stage) throws Exception {
stage.setTitle("Hello FX");
stage.setScene(new Scene(sp, 300, 100));
stage.sizeToScene();
stage.show();
}
@Override
public void stop() {
System.out.println("Hello FX application is stopped.");
}
}
Hello FX application is stopped.
Figure 11-1. The Windows Displayed by the HelloFX Application
Listing 11-2 contains the Nashorn script for the HelloFX application. It is a one-to-one
translation of the Java code in Listing 11-1. Notice that the code for the same application is
much shorter when written in Nashorn. The script is stored in the hellofx.js file. You can
run the script using the command prompt as follows and it will display the same window
as shown in Figure 11-1 :
jjs -fx hellofx.js
 
 
Search WWH ::




Custom Search