我使用FXML。我創建了一個按鈕來停止/重新啓動實時圖表。對於我使用時間軸的動畫。我想要從guiController(來自其他類)控制它,但它不起作用。我怎樣才能阻止其他課程的時間線?JavaFX停止時間線
謝謝!
FXML:
<Button id="button" layoutX="691.0" layoutY="305.0" mnemonicParsing="false" onAction="#btn_startmes" prefHeight="34.0" prefWidth="115.0" text="%start" />
guiController:
@FXML
private void btn_stopmes(ActionEvent event) {
MotionCFp Stopping = new MotionCFp();
Stopping.animation.stop();
}
MotionCFp.java:
@Override
public void start(final Stage stage) throws Exception {
else{
ResourceBundle motionCFp = ResourceBundle.getBundle("motionc.fp.Bundle", new Locale("en", "EN"));
AnchorPane root = (AnchorPane) FXMLLoader.load(MotionCFp.class.getResource("gui.fxml"), motionCFp);
final guiController gui = new guiController();
Scene scene = new Scene(root);
stage.setTitle(motionCFp.getString("title"));
stage.setResizable(false);
stage.setScene(scene);
root.getChildren().add(gui.createChart());
animation = new Timeline();
animation.getKeyFrames().add(new KeyFrame(Duration.millis(1000/60), new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent actionEvent) {
// 6 minutes data per frame
for(int count=0; count < 6; count++) {
gui.nextTime();
gui.plotTime();
animation.pause();
animation.play();
}
}
}));
animation.setCycleCount(Animation.INDEFINITE);
stage.show();
animation.play();
}
}
[timeline.stop()](http://docs.oracle.com/javafx/2/api/javafx/animation/Timeline.html#stop%28%29) - 我的猜測是你已經知道這個,但需要在你的問題中提供更多的信息(例如簡短的可執行示例代碼加描述),它說明了你的真正問題是什麼,以便有人可以提供更多的幫助。 – jewelsea
我試過了。我使用FXML,所以有一個guiControll,它處理例如按鈕操作。還有一個創建時間軸的主類。我無法從guiController啓動/停止/重新啓動動畫。如果時間軸開始(無限期),我無法用按鈕停止它。 – Miki
請在您的問題中包含FXML,控制器類和應用程序類的可執行代碼,以便可以複製問題。謝謝。 – jewelsea