2016-05-10 29 views
0

下面的代碼顯示了我的順序轉換的一部分功能,我希望使用Pslideshow.pause()使用戶能夠暫停幻燈片並繼續播放幻燈片。如何暫停JAVAFX的連續轉換

但是我意識到,一旦我使用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

您的下一張幻燈片是否等待用戶輸入? – ItachiUchiha

+0

@ItachiUchiha不,我把我的圖像存儲在LabelSlides []中,我只是從數據庫中檢索 –

+0

我在提問時應該已經清楚了。當你說「'Pslideshow.play()'將Pslideshow的狀態改變爲立即停止」。我不確定會發生什麼,你究竟是如何檢查狀態的? – ItachiUchiha

回答

0

該代碼是從我創建解釋SequentialTransition如何更改不同的狀態,即在運行SequentialTransitionStatus要旨複製,暫停,停止。

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); 
    } 
}