Book Example Updated for JavaFX Script SDK: HelloJFX
In response to the The JavaFX SDK Packages are Taking Shape post, a reader named John writes: "I started with the examples in your nice book. However, I see that many things have changed in JFX since then. E.g. javafx.ui.* classes have been replaced by javafx.ext.swing.* classes? And of course many examples do not run. Will you create an updated source of the examples of the book that run with the latest JFX update?"
I responded in agreement, so the next several blog posts are going to contain the examples from my JavaFX Script book, rewritten to work with the JavaFX SDK Technology Preview Release. The first one is the HelloJFX program, for which this is the UI:
By the way, the eBook version of the JavaFX Script book is available for download from this Apress site.
The Updated Code for HelloJFX
Here is the code, updated by a colleague and JavaFX developer named Matt Shirey:
* HelloJFX.fx - A JavaFX Script "Hello World" style example
* Developed 2007 by James L. Weaver (jim.weaver at jmentor dot com)
* Updated July 2008 by Matt Shirey (email@example.com) for JavaFX SDK Technology Preview 1
title: "Hello World-style example for JavaFX Script"
name: "Sans Serif"
content: "Hello JavaFX Script Developer!"
// Show the Frame on the screen
Running this Example
The JavaFX SDK Technology Preview branch of the compiler build may be downloaded here. This branch is what will become the JavaFX SDK Preview Release. After adding the openjfx-compiler-tp1/dist/bin directory to your PATH environment variable, and verifying that you have the Java Runtime Environment (JRE) 6 installed, use the following command at your operating system prompt to compile the program:
javafxc -d . HelloJFX.fx
To run the program, use the following command:
Have fun, and please post a comment if you have any questions!
JavaFX Script: Dynamic Java Scripting for Rich Internet/Client-side Applications
Immediate eBook (PDF) download available at the book's Apress site