| By James L. Weaver | Article Rating: |
|
| December 7, 2007 05:30 AM EST | Reads: |
9,530 |
/*
* ElephantInTheDoor.fx
* - A Compiled JavaFX Script example to congratulate
* the JavaFX Script compiler team for their talented
* and tireless efforts in "pushing the elephant
* through the door"
*
* Developed 2007 by James L. Weaver
* (jim.weaver at lat-inc dot com)
* to serve as a JavaFX Script example.
*/
import javafx.ui.*;
import javafx.ui.canvas.*;
class ElephantModel {
attribute color:Color = Color.LIGHTGREY;
}
var model =
ElephantModel {
};
Frame {
title: "The Elephant is Through the Door"
width: 400
height: 300
background: Color.WHITE
visible: true
menubar:
MenuBar {
menus: [
Menu {
text: "View"
items: [
MenuItem {
text: "Message..."
action:
function() {
MessageDialog {
title: "Message to JavaFX Compiler Team"
message: "Congratulations from the OpenJFX Community for
pushing the Elephant Through The Door!"
visible:true
};
}
}
]
},
Menu {
text: "Help"
items: [
MenuItem {
text: "About..."
action:
function() {
MessageDialog {
title: "About this Silly Elephant Example"
message: "Developed 2007 by James L. Weaver
(jim.weaver at lat-inc dot com)
to serve as a JavaFX Script example.
Elephant graphic by Deb Harper."
visible:true
};
}
}
]
}
]
}
content:
BorderPanel {
right:
Box {
orientation: Orientation.VERTICAL
content: [
Button {
text: "Grey"
action:
function() {
model.color = Color.LIGHTGREY
}
},
Button {
text: "Pink"
action:
function() {
model.color = Color.PINK
}
}
]
}
center:
Canvas {
content: [
Group {
content: [
Circle {
cx: 180
cy: 80
radius: 40
fill: bind model.color;
stroke: Color.GREY
strokeWidth: 10
},
Circle {
cx: 60
cy: 80
radius: 40
fill: bind model.color;
stroke: Color.GREY
strokeWidth: 10
},
Circle {
cx: 120
cy: 80
radius: 50
fill: bind model.color;
stroke: bind model.color;
strokeWidth: 2
},
Circle {
cx: 100
cy: 70
radius: 8
fill: Color.GREY
stroke: bind model.color;
strokeWidth: 2
},
Circle {
cx: 140
cy: 70
radius: 8
fill: Color.GREY
stroke: bind model.color;
strokeWidth: 2
},
Line {
x1: 105
y1: 90
x2: 105
y2: 128
stroke: Color.GREY
strokeWidth: 5
},
Line {
x1: 135
y1: 90
x2: 135
y2: 128
stroke: Color.GREY
strokeWidth: 5
},
Arc {
x: 15
y: 65
height: 120
width: 120
startAngle: 270
length: 90
closure: ArcClosure.PIE
stroke: Color.GREY
fill: bind model.color;
strokeWidth: 5
},
Arc {
x: 45
y: 95
height: 60
width: 60
startAngle: 270
length: 90
closure: ArcClosure.PIE
stroke: Color.GREY
fill: Color.WHITE
strokeWidth: 5
},
Line {
x1: 75
y1: 130
x2: 75
y2: 150
stroke: Color.WHITE
strokeWidth: 5
},
Line {
x1: 110
y1: 125
x2: 130
y2: 125
stroke: bind model.color;
//fill: bind model.color;
strokeWidth: 5
},
Line {
x1: 75
y1: 125
x2: 100
y2: 125
stroke: Color.WHITE
strokeWidth: 5
}
]
}
]
}
}
}
Differences from Interpreted JavaFX Script
There are very few differences between this compiled JavaFX Script example and how it would be written in interpreted JavaFX Script. They are:
- Compiled JavaFX Script uses static (class) variables to represent constants (e.g. Color.RED).
- Compiled JavaFX Script allows attribute initialization in the same statement as the attribute's declaration (e.g. attribute color:Color = Color.LIGHTGREY;).
- Operations and functions have been combined in compiled JavaFX Script, so each action attribute of the menu items and buttons are assigned an anonymous function, not an anonymous operation.
- The compiled version is stricter about not using an object where a sequence is required. For example, it is now necessary to use square brackets to enclose the body of the content attribute of the Canvas instance This is because the content attribute expects a sequence of Node objects (or a subclass like the Group object in this example).
As always, if you have any questions, please post a comment.
Published December 7, 2007 Reads 9,530
Copyright © 2007 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By James L. Weaver
James L. (Jim) Weaver is founder and president of jMentor, formed in 2000 to provide Java programming-related training to companies and individuals. He has served as a system architect and developer for over 25 years, specializing in leading-edge software development. His specialties include Java, object-oriented, and web-based technologies. He has authored books on the Java programming language, including most recently JavaFX Script, published by Apress.
- Kindle 2 vs Nook
- Cloud Computing on Gartner's Top 10 List and SYS-CON Events' 2010 Calendar
- Confessions of a Ulitzer Addict
- IBM Hardware Chief, Intel VC Exec Arrested in Insider Trading Scam
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Moving Your RIA Apps into the Cloud: Seven Challenges
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Windows 7 – Microsoft’s First Step to the Cloud
- Ulitzer Provides a Powerful Social Journalism Platform
- Jill Tummler Singer, Deputy CIO of CIA, Keynotes at GovIT Expo
- Open Source Mobile Cloud Sync and Push Email
- Kindle 2 vs Nook
- The Difference Between Web Hosting and Cloud Computing
- Cloud Computing on Gartner's Top 10 List and SYS-CON Events' 2010 Calendar
- Ajax in RichFaces 3.3, JSF 2 and RichFaces 4
- Confessions of a Ulitzer Addict
- IBM Hardware Chief, Intel VC Exec Arrested in Insider Trading Scam
- My Thoughts on Ulitzer
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- US Post Office Hops a Ride on NetSuite’s Cloud
- Moving Your RIA Apps into the Cloud: Seven Challenges
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Building a Drag-and-Drop Shopping Cart with AJAX
- What Is AJAX?
- Google Maps! AJAX-Style Web Development Using ASP.NET
- Flashback to January 2006: Exclusive SYS-CON.TV Interviews on "OpenAjax Alliance" Announcement
- AJAXWorld Conference & Expo to Take Place October 2-4, 2006, at the Santa Clara Convention Center, California
- AJAX Sponsor Webcasts Are Now Available at AJAXWorld Website
- How and Why AJAX, Not Java, Became the Favored Technology for Rich Internet Applications
- "Real-World AJAX" One-Day Seminar Arrives in Silicon Valley
- AJAXWorld University Announces AJAX Developer Bootcamp
- AJAX Support In JadeLiquid WebRenderer v3.1
- Where Are RIA Technologies Headed in 2008?
- Struts Validations Framework Using AJAX



































