【问题标题】:how to pause sequential transition of JAVAFX如何暂停 JAVAFX 的顺序转换
【发布时间】:2016-05-10 07:03:52
【问题描述】:

下面的代码显示了我的顺序转换的部分功能,我希望使用 Pslideshow.pause() 让用户能够暂停幻灯片并继续播放幻灯片。

但我意识到,一旦我使用 Pslideshow.play() ,当我单击我创建的窗格以显示幻灯片时,Pslideshow 的状态会立即变为已停止。

我应该怎么做才能让用户暂停并再次播放我的顺序转换?提前致谢!

public void start(){
for (Label slide : LabelSlides) {

    SequentialTransition sequentialTransition = new SequentialTransition();
    FadeTransition fadeIn = getFadeTransition(slide, 0.0, 1.0, 2000);
    PauseTransition stayOn = new PauseTransition(Duration.millis(2000));
    FadeTransition fadeOut = getFadeTransition(slide, 1.0, 0.0, 2000); 

    sequentialTransition.getChildren().addAll(fadeIn, stayOn, fadeOut);
    slide.setOpacity(0);
    this.root.setStyle("-fx-background-color: Black");
    this.root.getChildren().add(slide);
    Pslideshow.getChildren().add(sequentialTransition); 
    }

    Pslideshow.play();
}

@FXML 
public void PlaySlide(ActionEvent event) throws IOException
{   Node node=(Node) event.getSource();
    Stage stage=(Stage) node.getScene().getWindow();
    Stage newStage = new Stage();
    newStage.setWidth(stage.getWidth());
    newStage.setHeight(stage.getHeight());
    Scene_3Controller simpleSlideShow = new Scene_3Controller();      
    Scene scene = new Scene(simpleSlideShow.getRoot());
    MediaP.play();
    simpleSlideShow.start();       
    scene.setOnMouseClicked(new ClickHandler());      
    newStage.setScene(scene);
    newStage.show();
}  

【问题讨论】:

  • 您的下一张幻灯片是否等待用户输入?
  • @ItachiUchiha 不,我将图像存储在 LabelSlides[] 中,我只是从 db 中检索
  • 我在问这个问题时应该很清楚。当您说“Pslideshow.play() 将 Pslideshow 的状态更改为立即停止”时。我不确定这是否应该发生,您究竟是如何检查状态的?
  • @ItachiUchiha 哦,我在系统输出中添加了显示 Pslideshow 的状态。在start () 方法中,状态输出为running,然后在PlaySlide(Action) 方法中,它输出为stopped,我确实添加了一个点击处理程序,scene.setOnMouseClicked(new ClickHandler()); 它显示当我点击幻灯片时也停止了。
  • 您可以尝试使用this example 并评论哪个部分不适合您的实现吗?它显示了我们如何播放,即使在状态已更改为 STOPPED 后暂停 ST。

标签: java javafx transitions


【解决方案1】:

代码复制自我创建的SequentialTransitionStatus gist,用于解释 SequentialTransition 如何更改不同的状态,即 RUNNING、PAUSED、STOPPED。

import javafx.animation.FadeTransition;
import javafx.animation.PauseTransition;
import javafx.animation.SequentialTransition;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.util.Duration;

public class SequentialTransitionStatus extends Application {

    @Override
    public void start(Stage primaryStage) {

        Label slide = new Label("slide");
        slide.setOpacity(0);

        FadeTransition fadeIn = new FadeTransition(Duration.millis(2000), slide);
        fadeIn.setFromValue(0);
        fadeIn.setToValue(1);
        PauseTransition stayOn = new PauseTransition(Duration.millis(1000));
        FadeTransition fadeOut = new FadeTransition(Duration.millis(2000), slide);
        fadeOut.setFromValue(1);
        fadeOut.setToValue(0);
        SequentialTransition sequentialTransition = new SequentialTransition();
        sequentialTransition.getChildren().addAll(fadeIn, stayOn, fadeOut);

        Label status = new Label();
        status.textProperty().bind(sequentialTransition.statusProperty().asString());

        Button play = new Button("Play");
        play.setOnAction(event -> sequentialTransition.play());

        Button pause = new Button("Pause");
        pause.setOnAction(event -> sequentialTransition.pause());

        HBox hBox = new HBox(10, play, pause);
        hBox.setAlignment(Pos.CENTER);

        VBox box = new VBox(20, slide, hBox, status);
        box.setAlignment(Pos.CENTER);

        Scene scene = new Scene(box, 300, 250);
        primaryStage.setScene(scene);
        primaryStage.show();

    }

    public static void main(String[] args) {
        launch(args);
    }
}

【讨论】:

    猜你喜欢
    • 2021-01-20
    • 2016-10-12
    • 1970-01-01
    • 1970-01-01
    • 2020-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多