As I mentioned in the JFX and the Way Forward After JavaOne 2008 post, Sun announced at JavaOne that a preview release of the JavaFX SDK is scheduled to be available in July 2008. As a pleasant surprise over Memorial Day weekend, Sun opened up the development of this preview release SDK. This development activity is occurring as a part of the OpenJFX Compiler project, so follow the instructions that I gave you in the Obtaining the OpenJFX Script Compiler Just Got Easier post and join the fun! You'll be playing with the JavaFX SDK as it is being built, so expect changes. It would also be great if you'd provide input to the process, and help test the SDK as it's being developed.
Write Your First JavaFX Program that Uses the New javafx.gui Classes
Take a look at the JavaFX Script API Documentation and you'll notice that there are two sets of UI-related packages. The javafx.ui packages contains the older, prototype UI classes, and the javafx.gui packages contain the UI classes that will be in the JavaFX SDK. The JavaFX code below uses these newer UI classes, and I'll show you how to compile and run this code in a bit. When the application first starts up, an empty window appears with two buttons:
When you click the Hello button, the message "You say hello..." from the popular "Hello, Goodbye" Beatles song displays approximately in the center of the window:
When you click the Goodbye button, the message "and I say goodbye" appears in place of the former message:
Here's the JavaFX code that generated this user interface and functionality:
* HelloGoodbye.fx -
* A "Hello World" style program that demonstrates
* declaratively expressing a user interface.
title: "Hello, Goodbye"
content: bind phrase
// The button was clicked
phrase = "You say hello...";
phrase = "and I say goodbye";
Compiling and Running the Program
To compile this program, enter the following into the command line:
javafxc -d . HelloGoodbye.fx
As in Java, the -d option causes the CLASS files to be put into a directory corresponding to the package statement subordinate to the specified directory. To run the program, use the following command:
Now that you've got access to the JavaFX SDK as it's being built, get involved by writing JavaFX programs that exercise its functionality, and subscribe to one or more of the following mailing lists from this page.
JavaFXpert BootCamp in Oslo, Norway, on June 18-20, 2008
If you happen to be in the vicinity of Oslo, Norway later this month, please come to the free JavaFX Script seminar sponsored by Bouvet on June 18, 2008. I'll be teaching the seminar, followed by a two day JavaFXpert BootCamp. Contact Bouvet for information on registering for the BootCamp.
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