标签:rri vat tran prim tag ini start mat getch
import javafx.animation.Animation;
import javafx.animation.PathTransition;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TextArea;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Ellipse;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.util.Duration;
public class App16_9 extends Application {
private TextArea textArea = new TextArea("我喜欢用JavaFx编程");
@Override
public void start(Stage primaryStage) {
Pane pane = new Pane();
Text t = new Text("您好");
t.setFont(Font.font(20));
t.setFill(Color.RED);
Ellipse ellipse = new Ellipse(100, 60, 70, 40);
ellipse.setFill(Color.WHITE);
ellipse.setStroke(Color.BLUE);
pane.getChildren().addAll(ellipse, t);
//创建动画路径
PathTransition pathTransition = new PathTransition();
//设置播放的持续时间
pathTransition.setDuration(Duration.millis(4000));
//设置椭圆为路径
pathTransition.setPath(ellipse);
//设置t为动画节点
pathTransition.setNode(t);
pathTransition.setOrientation(PathTransition.OrientationType.ORTHOGONAL_TO_TANGENT);
//设置无限次播放
pathTransition.setCycleCount(Animation.INDEFINITE);
pathTransition.setAutoReverse(false);
pathTransition.play();
ellipse.setOnMousePressed(e -> pathTransition.pause());
ellipse.setOnMouseReleased(e -> pathTransition.play());
Scene scene = new Scene(pane, 800, 600);
primaryStage.setScene(scene);
primaryStage.setTitle("移动路径动画");
primaryStage.show();
}
public static void main(String[] args) {
Application.launch(args);
}
}
标签:rri vat tran prim tag ini start mat getch
原文地址:https://www.cnblogs.com/xl4ng/p/14406537.html