Adverts
Binding variables is the way you link two things together in JavaFX. The bind operator indicates to the environment that you want to receive incremental updates to the value of the item you are binding to - in other words when the bound object changes you want to know about it. This is shown in the example below which presents the user with a button to click. Each click increments a counter which is bound by the frame title. The title of the frame should reflect the number of times the button has been clicked.
import javafx.ui.*;
class ClickCountModel {
attribute count: Integer;
}
var clickCount = ClickCountModel {
count: 0
};
var win = Frame {
title: bind "Button clicked {clickCount.count} times - JavaFX"
width: 300
height: 300
content: Button {
text: "Click Me"
action: operation() {
clickCount.count++;
}
}
visible: true
};
Behind the scenes the bind is producing some sort of action listener and registering it with clickCount which is an instance of ClickCountModel. The great thing about declarative programming though is that we don't need to care how that is done - it just works.