Java FX (James Weaver)

10 June, 2008 at 13:22 6 comments

JavaFX is a family of products for creating Rich Internet Applications (RIAs) with immersive media and content. The JavaFX products include a runtime and tools suite that web scripters, designers and developers can use to quickly build and deliver expressive rich interactive applications for desktop, mobile, TV and other platforms. Currently JavaFX consists of JavaFX Script and JavaFX Mobile.

Sun Currently has an open source community project hosted for JavaFX, OpenJFX, where developers can sign up for a private preview of the JavaFX SDK, as well as download the JavaFX Script plugin for NetBeans 6.1.

In press previews for JavaFX, Sun Fellow James Gosling explained:

Most scripting languages are oriented at banging out Web pages. This is oriented around interfaces that are highly animated.

James Gosling,

There are parts of the world where a person’s desktop computer is their cell phone, and that’s the kind of end point that we’re going to get to,

James Gosling,

JavaFX is anticipated to compete on the desktop with Adobe AIR, OpenLaszlo, and Microsoft Silverlight. It may also target Blu-ray Disc’s interactive BD-J platform, although as yet no plans for a Blu-ray release have been announced.

Playing with the JavaFX SDK as it’s Being Built

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.
package beatles;
import javafx.gui.*;

Frame {
  var phrase:String
  title: "Hello, Goodbye"
  height: 300
  width: 400
  visible: true
    BorderPanel {
        Canvas {
            Text {
              x: 50
              y: 125
              content: bind phrase
                Font {
                  size: 36
        FlowPanel {
          content: [
            Button {
              text: "Hello"
                function():Void {
                  // The button was clicked
                  phrase = "You say hello...";
            Button {
              text: "Goodbye"
                function():Void {
                  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:

javafx beatles.HelloGoodbye

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.

JavaFX Script: Dynamic Java Scripting for Rich Internet/Client-side Applications
Immediate eBook (PDF) download available at the book’s Apress site


Bookmark and Share


Entry filed under: Java. Tags: , , .

SEO (Search Engine Optimization) Prototype JavaScript Framework

6 Comments Add your own

  • 1. Richard Monson-Haefel  |  11 June, 2008 at 17:05

    Nice post! I though it would be interesting to show the same program written in Curl.

    Curl is a RIA platform that’s been around almost as long as Java and has been very successful in Japan. It was just re-introduced to the US last year. It’s focused on RIA enterprise requirements and is in its 6th version. Very fast and fun to code – and seems less verbose than JavaFX.

    Here is the Curl Code

    {curl 7.0 applet}

    def content =
    {Frame font-size = 36px}

    {View title = "Hello, Goodbye",
    width = 400px, height = 300px, visibility = "normal",
    background = "#DDF",
    {on WindowClose do {exit}},

    {VBox margin = 6px,
    {HBox spacing = 6px,
    {CommandButton label = "Hello",
    {on Action do
    {content.add replace? = true,
    "You say hello..."}
    {CommandButton label = "Goodbye",
    {on Action do
    {content.add replace? = true,
    "and I say goodbye"}

  • 2. Maurizio Storani  |  11 June, 2008 at 17:32

    HI Richard
    I didn’t know Curl
    I’m going to spend all my spare time next week.


  • 3. Richard Monson-Haefel  |  11 June, 2008 at 19:18

    Cool! I’m glad your are interested. I posted my own blog comment about the comparison at:

    It provides the Curl source code and instructions on how to run it (pretty simple). It would be fun to see the same code written in other RIA technologies as a comparison to JavaFX and Curl.

  • 4. Ed O'Connor  |  13 June, 2008 at 18:06

    Here’s my stab at it in REBOL:

    REBOL [title: “Hello, Goodbye”]
    gui: layout [
    t: text 300 font-size 36 center “” return
    btn “Hello” [ t/text: “You say hello…” show t ]
    btn “Goodbye” [ t/text: “and I say goodbye” show t ]
    view center-face gui

    Or see:

  • 5. java master  |  1 March, 2011 at 22:50

    u suck!!!

  • 6. mario games  |  23 April, 2013 at 11:52

    I don’t even know how I ended up here, but I thought this post was great. I do not know who you are but definitely you’re going to a famous blogger if you are not already 😉 Cheers!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed

IT Passion’s Store



Get the Source
OSGi supporter
JUG Milano

Upcoming Events


Blog Stats

  • 371,507 hits

My PageRank

What's My Google PageRank?

%d bloggers like this: