
Primeramente creamos una aplicacion JavaFX


Una vez que se nos abre copiamos el siguiente código fuente
package javafxapplication3;
import javafx.animation.KeyFrame;
import javafx.animation.Interpolator;
import javafx.animation.Timeline;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;
import javafx.scene.control.Label;
import javafx.scene.control.TextBox;
import javafx.scene.layout.HBox;
var xRotar: Number = 0;
var anim = Timeline {
keyFrames: [
KeyFrame {
time: bind 2000ms
values: [
xRotar => 360 tween Interpolator.LINEAR,
]
}
]
};
Stage {
title: "Animación de Controles"
visible: true
scene: Scene {
width: 400
height: 500
content: [hBoxNombre,hBoxEmail, wsButton
]
}
def lblNombre = Label {
text: "Nombre:"
}
def txtNombre = TextBox {
columns: 12
selectOnFocus: true
}
def hBoxNombre = HBox {
layoutY: 10
content: [lblNombre, txtNombre]
rotate: bind xRotar
}
def lblEmail = Label {
text: "Email:"
}
def txtEmail = TextBox {
columns: 12
selectOnFocus: true
}
def hBoxEmail = HBox {
layoutY: 40
spacing: 10
rotate: bind xRotar
content: [lblEmail, txtEmail]
}
def wsButton = Button {
text: "Animar"
layoutY: 80
action: function (): Void {
anim.playFromStart();
}
}
}
Notas:
anim: Es usado para definir en el tiempo la respectiva animacion, para nuestro caso se ejecutará la animación por 2000 ms con una cuenta(interpolación) de 360
def: nos permite definir controles y asignarles variables fuera del Stage y luego estas variables son colocadas dentro del content del Stage
Finalmente ejecutamos el proyecto.
Damos click sobre el botón animar

En ese momento veremos el respectivo movimiento de los controles

No hay comentarios:
Publicar un comentario