本文概述
- 属性
- 构造函数
在JavaFX中, 类javafx.animation.PauseTransition表示此转换。我们只需要实例化此类即可创建适当的暂停过渡。
属性
属性 | 描述 | 设置方法 |
---|---|---|
duration | 它是Duration类的一种对象。它代表了过渡的生命周期。 | setDuration(Duration duration) |
- public PauseTransition():使用默认参数创建PauseTransition的新实例。
- public PauseTransition(Duration duration):使用指定的持续时间创建PauseTransition的新实例。
【JavaFX暂停过渡】在下面的示例中, 我们在多边形上应用了多个动画。每次转换后, 我们为节点提供了1秒的暂停。
package application;
import javafx.animation.FadeTransition;
import javafx.animation.PauseTransition;
import javafx.animation.RotateTransition;
import javafx.animation.SequentialTransition;
import javafx.animation.TranslateTransition;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Polygon;
import javafx.stage.Stage;
import javafx.util.Duration;
public class Pause_Transition extends Application{
@Override
public void start(Stage primaryStage) throws Exception {
// TODO Auto-generated method stub
//Creating polygon
Polygon poly = new Polygon();
poly.getPoints().addAll(new Double[] {320.0, 270.0, 270.0, 220.0, 270.0, 270.0, 320.0, 120.0, 370.0, 270.0, 370.0, 220.0});
//Setting Color and Stroke properties for the polygon
poly.setFill(Color.LIMEGREEN);
poly.setStroke(Color.BLACK);
//Setting Rotate Transition
RotateTransition rt = new RotateTransition(Duration.millis(500), poly);
rt.setByAngle(180);
rt.setCycleCount(2);
rt.setAutoReverse(true);
//Setting Translate Transition
TranslateTransition translate = new TranslateTransition(Duration.millis(500), poly);
translate.setToX(-150f);
translate.setCycleCount(2);
translate.setAutoReverse(true);
//Setting Fade Transition
FadeTransition fade = new FadeTransition(Duration.millis(500), poly);
fade.setFromValue(1.0f);
fade.setToValue(0.5f);
fade.setCycleCount(2);
fade.setAutoReverse(true);
//Setting Sequential Transition and pause after each transition passed in the list
SequentialTransition seqTransition = new SequentialTransition (fade, new PauseTransition(Duration.millis(2000)), rt, new PauseTransition(Duration.millis(2000)), translate);
//Playing Sequential Transition
seqTransition.play();
//Setting Group and scene
Group root = new Group();
root.getChildren().addAll(poly);
Scene scene = new Scene(root, 490, 300, Color.WHEAT);
primaryStage.setScene(scene);
primaryStage.setTitle("Pause Transition Example");
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
输出:
文章图片
推荐阅读
- JavaFX路径转换
- JavaFX并行过渡
- JavaFX PasswordField
- win8系统安装sql server软件后找不到怎样办
- win8系统怎样安装网络打印机|win8系统安装网络打印机的办法
- Win8安装软件提示“需要用管理员身份才能安装软件”怎样办
- Win8系统输入密钥后提示“处于通知模式”怎样办
- Win8安装office2007出现Osetup.DLL出错怎样办
- Win7/Win 8赶紧升级Win10,一年免费期过后要收费