« The JavaFX SDK Packages are Taking Shape | Main | JavaFX API Documentation Tool Now Supports In-line Examples »

July 03, 2008

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:

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

TrackBack

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

Listed below are links to weblogs that reference Book Example Updated for JavaFX Script SDK: HelloJFX:

Comments

I don't know why the example above doesn't work for me:
-NetBeans IDE 6.1 (Build 200804211638)
-1.6.0_03; Java HotSpot(TM) Client VM 1.6.0_03-b05

What's wrong? Has something change since July?

I had to make your code more like this:

package jfx_book;

import javafx.application.Frame;
import javafx.application.Stage;
import javafx.scene.text.Text;
import javafx.scene.FontStyle;
import javafx.scene.Font;


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

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.