JavaFX Script (for history)
It can be used in applets embedded in Web pages or in Java applications. It is concise and designed to visually describe a graphical interface and link it to functions of the application.
Based on the F3 language (Form Follows Function), acquired in 2005, Sun has developed JavaFX Script, a declarative language designed to describe graphical user interfaces, for the JavaFX framework mainly.
This language competes with XUL and XAML, but its syntax is close that of JavaScript, while the framework, whose version 1.0 is published in December 2008, is a competitor to Adobe AIR and Silverlight, other frameworks for Web applications.
Intended to develop GUIs, it has features to synchronize the graphical components of the interface with the data and a syntax five times more concise than Java.
Its goal is to combine rich text, graphics, animations, audio and video.
Update 2011. JavaFX Script is no longer supported since JavaFX 2.0 and thus is deprecated.
Java has been sold to Orable by Sun.
Features of the language
- Type: String, Number, Integer, Boolean, Void, Null, Duration.
- Types are not explicitely declared, they are deducted from what is assigned. The var or def keyword are used instead.
- Operators are those of Java.
- Everything is an expression.
- An object is defined by a literal according to the syntax of an array as JavaScript.
- {} Symbols have multiple uses. They are used to group content, to insert a variable in a string (PHP uses directly variable with its $ prefix). To concatenate strings.
- The same thing can be written in a declarative or procedural form.
- It can use existing Java classes.
Syntax
The procedural syntax is similar to JavaScript. The declarative syntax based on the API of the JavaFX framework allows to describe easily an interface.
Declaration of a function:
function display() { println("Hello!"); }
Without return type :
function display() : Void { println("Hello!"); }
Array:
var myArray = [ 1, 2, 3, 4 ]
JavaFX Script object:
Stage { title: "Declaring is easy!" width: 320 height: 240 visible: true }
The Stage objet allows to define a windows. Title and dimensions are added.
The same declaration may be written in a procedural form:
var myStage:Stage = new Stage(); myStage.title = "Declaring is easy!";
myStage.width = 320;
myStage.height = 240; myStage.visible = true;
Example
Hello world!
Stage { scene: Scene { content: Text { font: Font { size: 24 } x: 10 y: 30 content: "Hello World!" } } }
Displaying the content of an array.
var arr = [ 1, 2, 3, 4, 5] for(x in arr) { println(x); }