下面的代码显示了我的顺序转换功能的一部分,我希望使用 Pslideshow.pause()来启用用户暂停幻灯片并继续播放幻灯片。
但我意识到,一旦我使用 Pslideshow.play(),当我点击我创建的窗格以显示幻灯片时,Pslideshow的状态会立即变为Stopped。
我应该怎么做才能让用户暂停并再次播放我的顺序转换?提前谢谢!
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();
}
答案 0 :(得分:0)
从我创建的SequentialTransitionStatus 要点中复制代码,以解释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);
}
}