Tuesday, October 30th, 2007
Write your first JavaFX Script
Jim Weaver has posted a simple tutorial on writing your first JavaFX Script which discusses how you can use the JavaFX Pad to get it working.
-
-
/*
-
* HelloJFX.fx - A JavaFX Script "Hello World" style example
-
*
-
* Developed 2007 by James L. Weaver (jim.weaver at jmentor dot com)
-
*/
-
package jfx_book;
-
-
import javafx.ui.*;
-
import javafx.ui.canvas.*;
-
-
Frame {
-
title: "Hello World-style example for JavaFX Script"
-
height: 100
-
width: 400
-
content:
-
Canvas {
-
content:
-
Text {
-
font:
-
Font {
-
faceName: "Sans Serif"
-
style: BOLD
-
size: 24
-
}
-
x: 10
-
y: 10
-
content: "Hello JavaFX Script Developer!"
-
}
-
}
-
// Show the Frame on the screen
-
visible: true
-
}
-
// End of listing
-

Do you like the declarative code here?












I personally miss the tags… You know.
How about a “Css” file for that thing? instead of x,y parameters and “style:” in the middle of the code?
Whats wrong with HTML/CSS?
@Diego: Ha ha ha ha ha ha ha. Good one! Ha ha ha ha ha ha ha!
Dion,
I *really* appreciate that you posted my blog entry to ajaxian. To address one of the commenter’s “x, y” comments, I’d just like to say that hardcoding x / y positions is just for Hello World-style code like in this tutorial. JavaFX Script has some very easy to use layout widgets that enable doing cross-platform UI layouts in a simple, declarative manner. It also has some powerful binding capabilities that allow you to bind attributes such as x / y positions to dynamic attributes in a model. I touched on the binding concept in a post already (see http://learnjavafx.typepad.com/weblog/2007/10/now-that-youve-.html), and will cover layout widgets in a future post.
Thanks again,
Jim Weaver
“JavaFX Script: Dynamic Java Scripting for Rich Internet/Client-side Applications”
No. No I don’t
>Do you like the declarative code here?
Not particularly. It seems like XML would make it a little easier to follow.
Is there an XML version of this? or is everyone expected to do this layout in code like that?
mike chambers
Mike:
I’m no fan of layouts in code, but at least this syntax gives you some of the benefits of JSON in trade for being as brittle as code. XML is the worst of both worlds ;-)
Regards
PS: “Spam Question: What does the X in Ajax stand for?”. Heh.
Alex,
Personally, I prefer an XML based layout, with a DOM / parent / child API behind it.
That is why I was asking if there was an XML based version of the JavaFX stuff.
mike chambers
mesh@adobe.com
@mike chambers: I agree with you. XML is better for visual and human editors. FX Scripts adds another programmatic language to a complex architecture. What’s the benefit of FX Script? Why another programming language? Why not just use Java with XML templates?
I don’t like FX Script, and I will never join with it if I can.
Mike,
There is not an XML based version of JavaFX Script syntax. As shown, it is very lightweight and JSON-like.
Thanks,
Jim Weaver