« HelloJFXBind: Book Example Updated for JavaFX Script SDK | Main | SequenceExample: Book Example Updated for JavaFX Script SDK »

July 06, 2008

HelloJFXBind2: Book Example Updated for JavaFX Script SDK

As I mentioned earlier in the Book Example Updated for JavaFX Script SDK: HelloJFX post, several of the upcoming blog posts are going to contain the examples from my JavaFX Script book, rewritten to work with the JavaFX SDK Technology Preview Release.  For your convenience, I'm placing these posts in the JavaFX Script Book Examples category. Today's post contains the HelloJFXBind2 program, which builds upon the HelloJFXBind program to demonstrate putting a model in its own file.  Here is a screenshot of the UI:

Hellojfxbind2

By the way, the eBook version of the JavaFX Script book is available for download from this Apress site.

The Updated Code for HelloJFXBind2

This example program is comprised of two files.   Here is the code, updated by a colleague and JavaFX developer named Matt Shirey:

HelloJFXBind2.fx

/*
*  HelloJFXBind2.fx - A JavaFX Script "Hello World" style example
*                     binding to a model that is located in its own file.
*
*  Developed 2007 by James L. Weaver (jim.weaver at lat-inc 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.paint.*;
import javafx.scene.text.*;

/**
* This is a JavaFX Script that binds to data from the model.
*/
Frame {
  var hellojfxModel =
    HelloJFXModel {
      greeting: "Howdy JavaFX Script Developer!"
    }
  title: "JavaFX Script example that binds to a model"
  height: 100
  width: 400
  content:
    Canvas {
      content:
        Text {
          font:
            Font {
              name: "Sans Serif"
              style: FontStyle.BOLD_ITALIC
              size: 24
            }
          textOrigin: TextOrigin.TOP 
          // Put some color into the app
          stroke: Color.RED
          fill: Color.RED
          x: 10
          y: 10
          content: bind  hellojfxModel.greeting
        }
    }
  visible: true
}


HelloJFXModel.fx

/*
*  HelloJFXModel.fx - The model behind a JavaFX Script "Hello World" style
*                     example of binding.
*
*  Developed 2007 by James L. Weaver (jim.weaver at lat-inc.com)
*
*  Updated July 2008 by Matt Shirey (matt.shirey at lat-inc.com)
*  for JavaFX SDK Technology Preview 1
*/
package jfx_book;

/**
* This class serves as the model behind the user interface
*/
class HelloJFXModel {
  attribute greeting:String;
}

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 . *.fx

To run the program, use the following command:

javafx jfx_book.HelloJFXBind2

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/6a00e54f133d69883400e55387c0018833

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

Comments

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.