Java Reference
In-Depth Information
2. Next, we create an instance of Deck and add objects to its contents:
def w = 400;
def h = 320;
var scene:Scene;
def deck :Deck = Deck{
width:w-100 height:h-100
translateX:(w -(w-200))/2 translateY:(h-(h-100))/2
slideOffset:50
duration:300ms
roundCornerSize:20
}
deck. add ( Rectangle {width:150 height:100 fill:Color.RED});
deck. add ( Circle {radius:70 fill:Color.BLUE});
deck. add ( ImageView {
image:Image{url:"{__DIR__}image1.png"}fitWidth:200
preserveRatio:true
});
3. Lastly, we add interactions by creating buttons to animate the deck:
def leftBtn = Button {
text:"<<"
action:function(){
deck .shiftBackToFront();
}
}
def rightBtn = Button {
text:">>"
action:function(){
deck .shiftFrontToBack();
}
}
When the component is added to the stage, and the code is executed, you should see the
application as shown in the next screenshot. When the buttons are pressed, it slides the top
object (or bottom, depending on the button pressed) in the stack from the top to the bottom
of the stack (hard to capture with the screenshot).
 
Search WWH ::




Custom Search