Jim has posted 66 posts at DZone. You can read more from them at their website. View Full User Profile

Book Example Updated for JavaFX Script SDK: HelloJFX

07.08.2008
| 5653 views |
  • submit to reddit

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:

Hellojfx

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 (matt.shirey@lat-inc.com) for JavaFX SDK Technology Preview 1
*/
package jfx_book;

import javafx.ext.swing.*;
import javafx.scene.*;
import javafx.scene.text.*;

Frame {
title: "Hello World-style example for JavaFX Script"
height: 100
width: 400
content:
Canvas {
content:
Text {
font:
Font {
name: "Sans Serif"
style: FontStyle.BOLD
size: 24
}
x: 10
y: 10
textOrigin: TextOrigin.TOP
content: "Hello JavaFX Script Developer!"
}
}
// Show the Frame on the screen
visible: true
}

 

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:

javafx jfx_book.HelloJFX

Have fun, and please post a comment if you have any questions!
Jim Weaver
JavaFX Script: Dynamic Java Scripting for Rich Internet/Client-side Applications

Immediate eBook (PDF) download available at the book's Apress site

Published at DZone with permission of its author, Jim Weaver.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags: