如何在 javafx 2.4.0 中停止转换后触发事件?
How to trigger an event after transition stopped in javafx 2.4.0?
我的 PathTransition animates a a few labels and have an setOnFinished-事件。当使用光标输入标签时,此标签会动画并停止前一个标签的动画(如果有的话)。
Label l1 = new Label("Hello");
Label l2 = new Label("Hello");
Path path = new Path();
path.getElements().add(new MoveTo(100,100);
path.getElements().add(new LineTo(200,200));
PathTransition pathTransition = new PathTransition();
pathTransition.setDuration(Duration.millis(1000));
pathTransition.setPath(path);
pathTransition.setNode(l1);
pathTransition.setOnFinished(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
// do something
}
});
pathTransition.play()
// if i enter l2 i want stop the l1 animation
pathTransition.stop()
// animate the l2
// ...
我的问题是 pathTransition.stop() 停止了动画,但没有触发 onFinished 事件。 pathTransition停止后有没有触发事件的解决方案?
我希望我的问题是可以理解的。
谢谢
您可以监听对动画的 statusProperty
:
所做的更改
pathTransition.statusProperty().addListener(new ChangeListener<Status>() {
@Override
public void changed(ObservableValue<? extends Status> observableValue,
Status oldValue, Status newValue) {
if(newValue==Status.STOPPED){
//do something
}
}
});
我的 PathTransition animates a a few labels and have an setOnFinished-事件。当使用光标输入标签时,此标签会动画并停止前一个标签的动画(如果有的话)。
Label l1 = new Label("Hello");
Label l2 = new Label("Hello");
Path path = new Path();
path.getElements().add(new MoveTo(100,100);
path.getElements().add(new LineTo(200,200));
PathTransition pathTransition = new PathTransition();
pathTransition.setDuration(Duration.millis(1000));
pathTransition.setPath(path);
pathTransition.setNode(l1);
pathTransition.setOnFinished(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
// do something
}
});
pathTransition.play()
// if i enter l2 i want stop the l1 animation
pathTransition.stop()
// animate the l2
// ...
我的问题是 pathTransition.stop() 停止了动画,但没有触发 onFinished 事件。 pathTransition停止后有没有触发事件的解决方案?
我希望我的问题是可以理解的。
谢谢
您可以监听对动画的 statusProperty
:
pathTransition.statusProperty().addListener(new ChangeListener<Status>() {
@Override
public void changed(ObservableValue<? extends Status> observableValue,
Status oldValue, Status newValue) {
if(newValue==Status.STOPPED){
//do something
}
}
});