Java Reference
In-Depth Information
F The Deck.remove() function —as a measure of convenience, a remove function is
provided to remove node objects added to the stack easily.
F The stack shufle —the Deck class exposes the public functions
shiftBackToFront() and shiftFrontToBack() to trigger the shuffle animation
sequence. Function shiftBackToFront() picks a card from the bottom of the
stack and places it on top. Conversely, the function shiftFrontToBack() takes a
card from the top of the stack and slides it to the bottom.
Both functions use the internal animate() function to create the animation
sequence that slides the card out and back in the stack. This is accomplished by
using a simple TranslateTransition class that moves the card away from the
stack to a given distance (controlled by Deck property slideOffset ), then reverses
the animation sequence to bring the card back to the stack.
At the end of the initial slide sequence (away), the TranslateTransition calls
its internal function attached to the property action:function() to change
the Z-order of the card by moving it to the back using the toBack() function
(or toFront() , depending on the operation invoked).
F Using the Deck —to use the Deck class you simply create an instance of it and place
it in a scene graph. In the code, we assign an instance of Deck to the variable
deck , with a literal declaration that sets the properties slideOff , duration , and
roundCornerSize . Notice that we have access to Control -exposed properties such
as dimensions, translations, and so on.
To add cards to the deck, we invoke the Deck.add() function. In the code example,
we add several nodes to the deck including Shape instances and images using
ImageView (covered in Chapter 5 , JavaFX Media ). The nodes are stacked from
bottom to top, so the last node added is displayed and earlier nodes are hidden
behind it. The class automatically centers the node instance on the rectangle.
Finally, we add two buttons to drive the animation. The button labeled >> calls the
method Deck.frontToBack() , sliding the top card out and into the bottom of the
stack. The button labeled <<, on the other hand, slides the card from the bottom and
places it on top of the stack.
See also
F Chapter 1—Declaring and using JavaFX classes
F Chapter 1—Creating and using JavaFX functions
F Chapter 2—Creating your own custom node
F Chapter 2—Making your scripts modular
F Introduction
Search WWH ::

Custom Search