Java Reference
In-Depth Information
You can also declare change triggers on a variable. Change triggers are blocks of
JavaFX script that are called whenever the value of a variable changes. To
declare a change trigger, use the on replace syntax:
public var x:Number = 100 on replace {
println("New value is {x}");
};
public var width: Number on replace (old) {
println("Old value is {old}, New value is {x}");
}
Change triggers are discussed in more depth in Chapter 4 .
Sequences
Sequences are ordered lists of objects. Because ordered lists are used so often in
programming, JavaFX supports sequence as a first class feature. There is built-in
support in the language for declaring sequences, inserting, deleting, and modify-
ing items in the sequence. There is also powerful support for retrieving items
from the sequence.
Declaring Sequences
To declare a sequence, use square brackets with each item separated by a
comma. For example:
public def monthNames = ["January", "February", "March",
"April", "May", "June",
"July", August", "September",
"October", "November", "December"];
This sequence is a sequence of String s, because the elements within the brack-
ets are String s. This could have also been declared as
public def monthNames: String[] = [ "January", .....];
To assign an empty sequence, just use square brackets, [] . This is also the
default value for a sequence. For example, the following two statements both
equal the empty sequence.
public var nodes:Node[] = [];
public var nodes:Node[];
 
 
Search WWH ::




Custom Search