concept JavaFX Script in category java

appears as: JavaFX Script, The JavaFX Script, JavaFX Script, JavaFX Script
JavaFX in Action

This is an excerpt from Manning's book JavaFX in Action.

In layperson’s terms, JavaFX Script is a tool custom made for UI programming.

1.3. Comparing Java and JavaFX Script: “Hello JavaFX!”

So far we’ve discussed what JavaFX is and why it’s needed. We’ve looked at an example of JavaFX Script and seen that it’s very different from Java, but just how different? For a true side-by-side comparison to demonstrate the benefits of JavaFX Script over Java, we need to code the same program in both languages. Listings 1.2 and 1.3 do just that, and figure 1.7 compares them visually.

Listing 1.2. Hello World as JavaFX Script
import javafx.scene.Scene; import javafx.scene.text.*; import javafx.stage.Stage; Stage { title: "Hello World JavaFX" scene: Scene { content: Text { content: "Hello World!" font: Font { size: 30 } layoutX: 114 layoutY: 45 } } width:400 height:100 }

As the scale of the GUI increases, Java’s verbose syntax and disjointed structure (compared to the GUI structure) quickly become a handful, while JavaFX Script, a bit like the famous Energizer Bunny, can keep on going for far longer, thanks to its declarative syntax.

For readers unfamiliar with the Java platform, appendix D provides an overview, including how the “write once, run anywhere” promise is achieved, the different editions of Java, and the versions and revision names over the years. Although JavaFX Script is independent of Java as a language, it’s reliance on the Java runtime platform means background knowledge of Java is useful.

Figure 4.5. Model/View/Controller is achieved in JavaFX Script largely by way of bound expressions. Here one such expression depends on two strings for the contents of its SwingLabel.