Java Reference
In-Depth Information
step = 110;
println ("locX = {locX}");
step = 150;
println ("locX = {locX}");
When you run the application, you will get the following output:
locX = 100
locX = 110
locX = 150
Notice that the value of variable locX is synchronized with the value of variable step .
Whenever step is updated, locX changes in value automatically.
How it works...
The general syntax for binding looks like the following:
def variableX = bind expression
The idea behind binding is to keep variableX , on the left-hand side of the assignment,
updated whenever there is a change in the bound expression on the right-hand side.
JavaFX supports several forms of expression s which can be used to update the variable
on the left-hand side.
Binding to variables
This is the simplest form of the binding syntax where the variable on the left is bound to
other variables.
var x = 100;
def y = bind x + 10;
When the value of variable x changes, y is updated with the new value of x + 10 .
Binding to a conditional
JavaFX also supports conditional binding expressions, which update the left-hand side of
the assignment based on a predefined condition.
var x = 2;
def row = bind if((x mod 2) == 0) "even" else "odd";
for(n in [0..5]){
x = n;
println ("Row {n} is {row}");
}
 
Search WWH ::




Custom Search