Magazine
 
Quick Review:JavaFX
 
Working with JavaFX Classes and Objects
 

Iterating sequence using ‘for’ loop:

Sequence can be iterated using ‘for’ operator.

For example, the code below:

var values = [1..5];
for (i in values){
java.lang.System.out.println(“value: “+i);
}

Gives output as below:

value: 1
value: 2
value: 3
value: 4
value: 5

xi) Data Binding:

Data binding is one of the important feature of JavaFX. The general syntax of using ‘bind’ is:

var myVariable = bind myExpression;

In the above syntax, variable ‘myVariable’ is bound to the value of the expression ‘myExpression’. As the value of the expression ‘myExpression’ changes, the changes also reflect to the value of the variable ‘myVariable’.

For example, in the code below the radius of the circle is bound to the expression (X+Y)/2. When the expression value is changed due to changes in value of the variables X Or Y, the radius of the circle also changes.

import javafx.scene.geometry.Circle;
import javafx.scene.paint.Color;
import javafx.ext.swing.*;
var x = 20;
var y = 20;
SwingFrame {
title: “Bind Example”
width: 200
height: 200

Aug 2008 | Java Jazz Up |27
 
previous
index
next
 
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,

58, 59, 60, 61, 62, 63 Download PDF