javafx transition with acceleration code example
Example 1: transition java fx
import javafx.animation.TranslateTransition;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.util.Duration;
public class FxTransitionExample3 extends Application
{
public static void main(String[] args)
{
Application.launch(args);
}
@Override
public void start(Stage stage)
{
Text text = new Text("A Translate Transition Example");
text.setFont(Font.font(36));
VBox root = new VBox(text);
root.setPrefSize(500, 100);
root.setStyle("-fx-padding: 10;" +
"-fx-border-style: solid inside;" +
"-fx-border-width: 2;" +
"-fx-border-insets: 5;" +
"-fx-border-radius: 5;" +
"-fx-border-color: blue;");
Scene scene = new Scene(root);
stage.setScene(scene);
stage.setTitle("Scrolling Text using a Translate Transition");
stage.show();
TranslateTransition trans = new TranslateTransition(Duration.seconds(2), text);
trans.setFromX(scene.getWidth());
trans.setToX(-1.0 * text.getLayoutBounds().getWidth());
trans.setCycleCount(TranslateTransition.INDEFINITE);
trans.setAutoReverse(true);
trans.play();
}
}
Example 2: transition java fx
import javafx.animation.FadeTransition;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.util.Duration;
public class FxTransitionExample1 extends Application
{
public static void main(String[] args)
{
Application.launch(args);
}
@Override
public void start(Stage stage)
{
Rectangle rect = new Rectangle(400, 200, Color.GREEN);
HBox root = new HBox(rect);
root.setStyle("-fx-padding: 10;" +
"-fx-border-style: solid inside;" +
"-fx-border-width: 2;" +
"-fx-border-insets: 5;" +
"-fx-border-radius: 5;" +
"-fx-border-color: blue;");
Scene scene = new Scene(root);
stage.setScene(scene);
stage.setTitle("A Fade-in and Fade-out Transition Example");
stage.show();
FadeTransition trans = new FadeTransition(Duration.seconds(2), rect);
trans.setFromValue(1.0);
trans.setToValue(.20);
trans.setCycleCount(FadeTransition.INDEFINITE);
trans.setAutoReverse(true);
trans.play();
}
}