Earlier in this weblog, I showed you an example from my JavaFX Script book that contains multiple FX source files. Yesterday the JavaFX Script compiler team added the capabilities required to port that example to compiled JavaFX Script. Please take some time to look at the original example and its explanation at the link provided above. Then take a look at this ported example, followed by an explanation of how to compile and run it:
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 dot com)
*/
package jfx_book;
/**
* This class serves as the model behind the user interface
*/
class HelloJFXModel {
attribute greeting:String;
}
HelloJFXBind2.fx
/*
* HelloJFXBind2.fx - A Compiled 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)
*/
package jfx_book;
import javafx.ui.*;
import javafx.ui.canvas.*;
/**
* 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
background: Color.WHITE
content:
Canvas {
content: [
Text {
font:
Font {
faceName: "Sans Serif"
// Example of an attribute with a collection of values
style: [
FontStyle.BOLD,
FontStyle.ITALIC
]
size: 24
}
// Put some color into the app
stroke: Color.RED
fill: Color.RED
x: 10
y: 10
content: bind hellojfxModel.greeting
}
]
}
visible: true
}
Because these source files are in the jfx_book
package, place these files in that directory. Then navigate to that directory and run the following command:
javafxc HelloJFXModel.fx HelloJFXBind2.fx
Alternatively, you could use a wildcard:
javafxc *.fx
After successfully compiling the source files, navigate to the directory in which the top node of the package is located and run the javafx command as usual to execute the program:
javafx jfx_book.HelloJFXBind2
The output of the program should look similar to the interpreted version:
By the way, this and upcoming posts are going to be code-intensive so that you'll feel comfortable writing your own compiled JavaFX Script program in response to the challenge that I gave you yesterday.
Enjoy,
Jim Weaver
JavaFX Script: Dynamic Java Scripting for Rich Internet/Client-side Applications
eBook (PDF) download immediately available at the book's Apress site
Get the best out os the best by going to http://w-aw.com , get WareZ for free, just search, or go to one of the topics and get that thing. Its ALL FREE! Scripts like Able Dating 2.4 NULLED! is NOW! available. Also the latest version of vBulletin and mods are now available. WaW Info :- 14000+ FREE SCRIPTS, 3400+ FREE TEMPLATES, 9000+ FREE COMPONENTS, 1000+ FREE MOVIES, 1800+ FREE TOOLS, 7400+ FREE ICONS, 3200+ FREE SONGS, 16000+ FREE APPLICATIONS, 70000 NEWS REPORT, 1900 SEO TOOLS, 8000 GAMES FOR PC, PS2/3, XBOX, XBOX LIVE, MOBILE, PSP AND LOADS MORE. Http://w-aw.com
Posted by: Sunite | June 16, 2008 at 03:55 PM