Java Reference
In-Depth Information
The definition of the preceding number variable performs two things:
1. It binds number to space.number . Whenever the value of space.number
changes, number will automatically change accordingly.
2. The number variable uses a trigger to force an update to the value of space-
Image whenever number changes too. In this case, spaceImage points to a
sequence (a cache) of Image s indexed by the value of number .
Finally, each SpaceNode defines an instance of ImageView , which is ultimately
how the image is displayed. It looks something like this:
ImageView {
...
image: bind spaceImage
...
}
Now, the image for a SpaceNode will dynamically change whenever space.number
changes. Here's the chain of events:
• The user enters a number into an editable space.
• The space.number instance variable is assigned a new value.
• The corresponding SpaceNode has a number instance variable that is
bound to space.number . Whenever space.number changes, so does this
number variable.
• There is a trigger associated with the number instance variable such that
whenever it is modified, it causes the spaceImage variable to be recalcu-
lated. In this case, spaceImage uses number as an index into a sequence of
cached Image s.
•Each SpaceNode instantiates ImageView . Its image instance variable is
bound to spaceImage . Whenever spaceImage changes, the image will
change too.
This all comes about because of the capabilities of binding and triggers.
Interfacing with Java Components
So far, we've covered the logic and presentation of our Sudoku application, and
how these two worlds relate to one another. The components comprising this
portion of our application were written in JavaFX and represent the main effort
in creating JavaFX Sudoku. There is a third element, however, which needs to be
 
Search WWH ::




Custom Search