Java Reference
In-Depth Information
Here, the code block is executed when the variable on the left-hand side of the assignment
is updated. The oldValueVarName variable name is optional and holds the value of variable
before the update.
Using triggers
The following is a simple trigger example. You can see the full code listing for this code at
ch01/source-code/src/binding/TriggerDemo.fx .
def X_BOUND = 10;
var locX = 7 on replace oldX {
if(locX <= X_BOUND) {
println ("{oldX} ==> {locX}, in bound");
}else{
println ("{oldX} ==> {locX}, Out of bound!");
}
}
locX = 12;
locX = 4;
Whenever the value of variable locX is updated (including the initial assignment), the on
replace trigger is executed as well.
0 ==> 7, in bound
7 ==> 12, out of bound!
12 ==> 4, in bound
See also
F Declaring and using variables in JavaFX
Creating and using JavaFX functions
One of the types supported by JavaFX is named a function-type. To be clear, this is not the
type of the returned value of the function, but rather an actual data type that represents
a function. This versatility throws JavaFX squarely in the realm of functional programming,
where functions are regarded as first-order data types and can be manipulated just like any
other supported data types. This section shows you how to create functions in JavaFX and use
them as expressions in your code.
Getting ready
The concepts presented here discuss functions as an executable code unit that can be
assigned and reused. You are expected to know the general purpose of a function and how
to use it. If you have written any code before, you most likely know how to create and use
a function.
 
Search WWH ::




Custom Search