« Video of Cool JavaFX Demos at JavaOne 2008 | Main | Check out the JavaFX Script Documentation »

June 09, 2008

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 Classes

The JavaFX code below uses the 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:

Blank

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:

Hello

When you click the Goodbye button, the message "and I say goodbye" appears in place of the former message:

Goodbye

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.ext.swing.BorderPanel;
import javafx.ext.swing.Button;
import javafx.ext.swing.Canvas;
import javafx.ext.swing.FlowPanel;
import javafx.ext.swing.Frame;
import javafx.scene.Font;
import javafx.scene.text.Text;

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

users@openjfx-compiler.dev.java.net

gui@openjfx-compiler.dev.java.net

dev@openjfx-compiler.dev.java.net

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

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00e54f133d69883400e552b058c78834

Listed below are links to weblogs that reference Playing with the JavaFX SDK as it's Being Built:

Comments

Thanks for the lightning-fast response!

Yes, the Eclipse plug-in is not up to date. NetBeans is, and of course you can use the command-line tools.

Using the JavaFX plugin for Eclipse, I see this error:

11: Encountered "title" at line 11, column 3.
Was expecting one of:
"*" ...
"?" ...
"+" ...
"=" ...

This error points to the word 'title' in the first couple of lines of the program:

var phrase:String
title: "Hello, Goodbye"

Is the compiler for the Eclipse plugin not up to date?

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment

My Photo

Upcoming Speaking Engagements:


  • Stephen Chin and Jim Weaver speaking about JavaFX Platform

  • Speaking on JavaFX and Java at Øredev in Malmö, Sweden on 2-6 November, 2009

Upcoming JavaFX Training:


  • Developing Secure, Rich Internet Applications Hosted on a Variety of Clients Using JavaFX Technology

Enter your email address:

Delivered by FeedBurner

Available now as early access eBook


  • Click book image above to obtain eBook

Twitter Updates

    follow me on Twitter

    Affiliations:

    DZone Links:


    July 2009

    Sun Mon Tue Wed Thu Fri Sat
          1 2 3 4
    5 6 7 8 9 10 11
    12 13 14 15 16 17 18
    19 20 21 22 23 24 25
    26 27 28 29 30 31  

    Disclaimer:

    • By reading this site, you are agreeing that under no circumstances will Veriana Networks, Inc. or its affiliates be responsible for (1) any information contained on or omitted from the site, (2) any person's reliance on any such information, whether or not the information is correct, current or complete, (3) the consequences of any action you or any other person takes or fails to take, whether or not based on information provided by or as a result of the use of the sites.