本文整理匯總了Java中javafx.animation.Timeline.setOnFinished方法的典型用法代碼示例。如果您正苦於以下問題:Java Timeline.setOnFinished方法的具體用法?Java Timeline.setOnFinished怎麽用?Java Timeline.setOnFinished使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javafx.animation.Timeline
的用法示例。
在下文中一共展示了Timeline.setOnFinished方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: playCrossfade
import javafx.animation.Timeline; //導入方法依賴的package包/類
private void playCrossfade(final List<? extends Playable> items, final int index) {
MediaPlayer oldPlayer = currentPlayer;
final double currentVolume = oldPlayer.getVolume();
oldPlayer.volumeProperty().unbind();
playQueue = new ArrayList<>(items);
currentIndex = index;
MediaPlayer newPlayer = new MediaPlayer(new Media(playQueue.get(currentIndex).getUri().toString()));
newPlayer.setVolume(0);
newPlayer.play();
Timeline crossfade = new Timeline(new KeyFrame(Duration.seconds(CROSSFADE_DURATION),
new KeyValue(oldPlayer.volumeProperty(), 0),
new KeyValue(newPlayer.volumeProperty(), currentVolume)));
crossfade.setOnFinished(event -> {
oldPlayer.stop();
setCurrentPlayer(newPlayer);
});
crossfade.play();
}
示例2: ChartData
import javafx.animation.Timeline; //導入方法依賴的package包/類
public ChartData(final String NAME, final double VALUE, final Color FILL_COLOR, final Color STROKE_COLOR, final Color TEXT_COLOR, final Instant TIMESTAMP, final boolean ANIMATED, final long ANIMATION_DURATION) {
name = NAME;
value = VALUE;
oldValue = 0;
fillColor = FILL_COLOR;
strokeColor = STROKE_COLOR;
textColor = TEXT_COLOR;
timestamp = TIMESTAMP;
currentValue = new DoublePropertyBase(value) {
@Override protected void invalidated() {
oldValue = value;
value = get();
fireChartDataEvent(UPDATE_EVENT);
}
@Override public Object getBean() { return ChartData.this; }
@Override public String getName() { return "currentValue"; }
};
timeline = new Timeline();
animated = ANIMATED;
animationDuration = ANIMATION_DURATION;
timeline.setOnFinished(e -> fireChartDataEvent(FINISHED_EVENT));
}
示例3: makeText
import javafx.animation.Timeline; //導入方法依賴的package包/類
private static void makeText(Stage ownerStage, String toastMsg, int toastDelay) {
Stage toastStage = new Stage();
toastStage.initOwner(ownerStage);
toastStage.setResizable(false);
toastStage.initStyle(StageStyle.TRANSPARENT);
Text text = new Text(toastMsg);
text.setFont(Font.font("Verdana", 20));
text.setFill(Color.BLACK);
StackPane root = new StackPane(text);
root.setStyle("-fx-background-radius: 20; -fx-background-color: rgba(255, 255, 255, 0.9); -fx-padding: 20px;");
root.setOpacity(0);
Scene scene = new Scene(root);
scene.setFill(Color.TRANSPARENT);
toastStage.setScene(scene);
toastStage.show();
Timeline fadeInTimeline = new Timeline();
KeyFrame fadeInKey1 = new KeyFrame(Duration.millis(200), new KeyValue(toastStage.getScene().getRoot().opacityProperty(), 1));
fadeInTimeline.getKeyFrames().add(fadeInKey1);
fadeInTimeline.setOnFinished((ae) -> new Thread(() -> {
try {
Thread.sleep(toastDelay);
} catch (InterruptedException e) {
e.printStackTrace();
}
Timeline fadeOutTimeline = new Timeline();
KeyFrame fadeOutKey1 = new KeyFrame(Duration.millis(500), new KeyValue(toastStage.getScene().getRoot().opacityProperty(), 0));
fadeOutTimeline.getKeyFrames().add(fadeOutKey1);
fadeOutTimeline.setOnFinished((aeb) -> toastStage.close());
fadeOutTimeline.play();
}).start());
fadeInTimeline.play();
}
示例4: setupShowAnimation
import javafx.animation.Timeline; //導入方法依賴的package包/類
@Override
protected Timeline setupShowAnimation() {
Timeline tl = new Timeline();
// Sets opacity to 0.0 instantly which is pretty much invisible
KeyValue kvOpacity = new KeyValue(stage.opacityProperty(), 0.0);
KeyFrame frame1 = new KeyFrame(Duration.ZERO, kvOpacity);
// Sets opacity to 1.0 (fully visible) over the time of 3000 milliseconds.
KeyValue kvOpacity2 = new KeyValue(stage.opacityProperty(), 1.0);
KeyFrame frame2 = new KeyFrame(Duration.millis(3000), kvOpacity2);
tl.getKeyFrames().addAll(frame1, frame2);
tl.setOnFinished(e -> trayIsShowing = true);
return tl;
}
示例5: setupDismissAnimation
import javafx.animation.Timeline; //導入方法依賴的package包/類
@Override
protected Timeline setupDismissAnimation() {
Timeline tl = new Timeline();
KeyValue kv1 = new KeyValue(stage.yLocationProperty(), stage.getY() + stage.getWidth());
KeyFrame kf1 = new KeyFrame(Duration.millis(2000), kv1);
KeyValue kv2 = new KeyValue(stage.opacityProperty(), 0.0);
KeyFrame kf2 = new KeyFrame(Duration.millis(2000), kv2);
tl.getKeyFrames().addAll(kf1, kf2);
tl.setOnFinished(e -> {
trayIsShowing = false;
stage.close();
stage.setLocation(stage.getBottomRight());
});
return tl;
}
示例6: ChartItem
import javafx.animation.Timeline; //導入方法依賴的package包/類
public ChartItem(final String NAME, final double VALUE, final Color FILL, final Color STROKE, final Color TEXT_COLOR, final Instant TIMESTAMP, final boolean ANIMATED, final long ANIMATION_DURATION) {
_name = NAME;
_value = VALUE;
oldValue = 0;
_fill = FILL;
_stroke = STROKE;
_textColor = TEXT_COLOR;
_timestamp = TIMESTAMP;
_symbol = Symbol.NONE;
_animated = ANIMATED;
currentValue = new DoublePropertyBase(_value) {
@Override protected void invalidated() {
oldValue = getValue();
setValue(get());
fireItemEvent(UPDATE_EVENT);
}
@Override public Object getBean() { return ChartItem.this; }
@Override public String getName() { return "currentValue"; }
};
timeline = new Timeline();
animationDuration = ANIMATION_DURATION;
timeline.setOnFinished(e -> fireItemEvent(FINISHED_EVENT));
}
示例7: startAnimateForm300
import javafx.animation.Timeline; //導入方法依賴的package包/類
private Timeline startAnimateForm300() {
Timeline tml = new Timeline(
new KeyFrame(Duration.ZERO, new KeyValue(pnlContent.maxHeightProperty(), 70)),
new KeyFrame(Duration.seconds(0.4), new KeyValue(pnlContent.maxHeightProperty(), 300, Interpolator.EASE_BOTH)));
tml.setOnFinished((ActionEvent event) -> {
pnlForm.setVisible(true);
txtSend.requestFocus();
});
return tml;
}
示例8: startAnimateForm130
import javafx.animation.Timeline; //導入方法依賴的package包/類
private Timeline startAnimateForm130() {
Timeline tml = new Timeline(
new KeyFrame(Duration.ZERO, new KeyValue(pnlContent.maxHeightProperty(), 70)),
new KeyFrame(Duration.seconds(0.4), new KeyValue(pnlContent.maxHeightProperty(), 130, Interpolator.EASE_BOTH)));
tml.setOnFinished((ActionEvent event) -> {
pnlForm.setVisible(false);
pnlMessage.setVisible(true);
});
return tml;
}
示例9: commitCrime
import javafx.animation.Timeline; //導入方法依賴的package包/類
@FXML
void commitCrime(ActionEvent event) {
crimeBtn.setDisable(true);
JFXRadioButton selectedRadio = (JFXRadioButton) group.getSelectedToggle();
String extractedCrime = selectedRadio.getText();
/*
Extract the selected crime from the selected radio button's text or bindIt and pass it to the GameEngine. */
GameEngine.game().isSuccessful(extractedCrime);
Timeline timeline = new Timeline();
for (int i = 0; i <= seconds; i++) {
final int timeRemaining = seconds - i;
KeyFrame frame = new KeyFrame(Duration.seconds(i),
e -> {
crimeBtn.setDisable(true);
crimeBtn.setText("Wait " + timeRemaining + " sec..");
});
timeline.getKeyFrames().add(frame);
}
timeline.setOnFinished(e -> {
crimeBtn.setText("Commit!");
crimeBtn.setDisable(false);
refresh();
seconds += 5;
});
timeline.play();
}
示例10: moveCircle
import javafx.animation.Timeline; //導入方法依賴的package包/類
private void moveCircle(Circle C) {
double centerX = (scene.getWidth() - maxRadius) * Math.random() + maxRadius;
double centerY = scene.getHeight();
C.setCenterX(centerX);
//C.setTranslateY((scene.getHeight() - maxRadius) * Math.random() + maxRadius);
C.setCenterY(centerY);
double radius = (maxRadius - minRadius) * Math.random() + minRadius;
C.setFill(new Color(Math.random(), Math.random(), Math.random(), 1));
C.setRadius(radius);
Timeline timeline = new Timeline();
double timelength = ((maxTimeLength - minTimeLength) * Math.random() + minTimeLength) * 1000;
timeline.getKeyFrames().add(new KeyFrame(new Duration(timelength), new KeyValue(C.centerYProperty(), 0 - maxRadius, Interpolator.EASE_IN)));
/* SequentialTransition sequence = new SequentialTransition();
for(int i = 0; i < 10; i++) {
sequence.getChildren().add(new KeyFrame(new Duration(timelength / 10), new KeyValue(C.centerXProperty(), centerX - 100)));
sequence.getChildren().add(new KeyFrame(new Duration(timelength / 10), new KeyValue(C.centerXProperty(), centerX + 100)));
}*/
timeline.play();
timeline.setOnFinished(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
//moveCircle(C);
newCircle();
}
});
}
示例11: setupDismissAnimation
import javafx.animation.Timeline; //導入方法依賴的package包/類
@Override
protected Timeline setupDismissAnimation() {
Timeline tl = new Timeline();
// At this stage the opacity is already at 1.0
// Lowers the opacity to 0.0 within 2000 milliseconds
KeyValue kv1 = new KeyValue(stage.opacityProperty(), 0.0);
KeyFrame kf1 = new KeyFrame(Duration.millis(2000), kv1);
tl.getKeyFrames().addAll(kf1);
// Action to be performed when the animation has finished
tl.setOnFinished(e -> {
trayIsShowing = false;
stage.close();
stage.setLocation(stage.getBottomRight());
});
return tl;
}
示例12: setupShowAnimation
import javafx.animation.Timeline; //導入方法依賴的package包/類
@Override
protected Timeline setupShowAnimation() {
Timeline tl = new Timeline();
// Sets the x location of the tray off the screen
double offScreenX = stage.getOffScreenBounds().getX();
KeyValue kvX = new KeyValue(stage.xLocationProperty(), offScreenX);
KeyFrame frame1 = new KeyFrame(Duration.ZERO, kvX);
// Animates the Tray onto the screen and interpolates at a tangent for 300 millis
Interpolator interpolator = Interpolator.TANGENT(Duration.millis(300), 50);
KeyValue kvInter = new KeyValue(stage.xLocationProperty(), stage.getBottomRight().getX(), interpolator);
KeyFrame frame2 = new KeyFrame(Duration.millis(1300), kvInter);
// Sets opacity to 0 instantly
KeyValue kvOpacity = new KeyValue(stage.opacityProperty(), 0.0);
KeyFrame frame3 = new KeyFrame(Duration.ZERO, kvOpacity);
// Increases the opacity to fully visible whilst moving in the space of 1000 millis
KeyValue kvOpacity2 = new KeyValue(stage.opacityProperty(), 1.0);
KeyFrame frame4 = new KeyFrame(Duration.millis(1000), kvOpacity2);
tl.getKeyFrames().addAll(frame1, frame2, frame3, frame4);
tl.setOnFinished(e -> trayIsShowing = true);
return tl;
}
示例13: setupDismissAnimation
import javafx.animation.Timeline; //導入方法依賴的package包/類
@Override
protected Timeline setupDismissAnimation() {
Timeline tl = new Timeline();
double offScreenX = stage.getOffScreenBounds().getX();
Interpolator interpolator = Interpolator.TANGENT(Duration.millis(300), 50);
double trayPadding = 3;
// The destination X location for the stage. Which is off the users screen
// Since the tray has some padding, we want to hide that too
KeyValue kvX = new KeyValue(stage.xLocationProperty(), offScreenX + trayPadding, interpolator);
KeyFrame frame1 = new KeyFrame(Duration.millis(1400), kvX);
// Change the opacity level to 0.4 over the duration of 2000 millis
KeyValue kvOpacity = new KeyValue(stage.opacityProperty(), 0.4);
KeyFrame frame2 = new KeyFrame(Duration.millis(2000), kvOpacity);
tl.getKeyFrames().addAll(frame1, frame2);
tl.setOnFinished(e -> {
trayIsShowing = false;
stage.close();
stage.setLocation(stage.getBottomRight());
});
return tl;
}
示例14: buildEvent
import javafx.animation.Timeline; //導入方法依賴的package包/類
private EventHandler<Event> buildEvent() {
return new EventHandler<Event>() {
@Override
public void handle(Event e) {
if (turned)
return;
if (e.getEventType() == MouseEvent.MOUSE_ENTERED || e.getEventType() == GazeEvent.GAZE_ENTERED) {
progressIndicator.setOpacity(1);
progressIndicator.setProgress(0);
Timeline timelineCard = new Timeline();
timelineCard.getKeyFrames().add(new KeyFrame(new Duration(1),
new KeyValue(card.xProperty(), card.getX() - (initWidth * zoom_factor - initWidth) / 2)));
timelineCard.getKeyFrames().add(new KeyFrame(new Duration(1),
new KeyValue(card.yProperty(), card.getY() - (initHeight * zoom_factor - initHeight) / 2)));
timelineCard.getKeyFrames().add(
new KeyFrame(new Duration(1), new KeyValue(card.widthProperty(), initWidth * zoom_factor)));
timelineCard.getKeyFrames().add(new KeyFrame(new Duration(1),
new KeyValue(card.heightProperty(), initHeight * zoom_factor)));
timelineProgressBar = new Timeline();
timelineProgressBar.getKeyFrames().add(new KeyFrame(new Duration(fixationlength),
new KeyValue(progressIndicator.progressProperty(), 1)));
timelineCard.play();
timelineProgressBar.play();
timelineProgressBar.setOnFinished(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
turned = true;
card.setFill(new ImagePattern(image, 0, 0, 1, 1, true));
card.removeEventFilter(MouseEvent.ANY, enterEvent);
card.removeEventFilter(GazeEvent.ANY, enterEvent);
if (winner) {
onCorrectCardSelected();
} else {// bad card
onWrongCardSelected();
}
}
});
} else if (e.getEventType() == MouseEvent.MOUSE_EXITED || e.getEventType() == GazeEvent.GAZE_EXITED) {
Timeline timeline = new Timeline();
timeline.getKeyFrames().add(new KeyFrame(new Duration(1),
new KeyValue(card.xProperty(), card.getX() + (initWidth * zoom_factor - initWidth) / 2)));
timeline.getKeyFrames().add(new KeyFrame(new Duration(1),
new KeyValue(card.yProperty(), card.getY() + (initHeight * zoom_factor - initHeight) / 2)));
timeline.getKeyFrames()
.add(new KeyFrame(new Duration(1), new KeyValue(card.widthProperty(), initWidth)));
timeline.getKeyFrames()
.add(new KeyFrame(new Duration(1), new KeyValue(card.heightProperty(), initHeight)));
timeline.play();
timelineProgressBar.stop();
progressIndicator.setOpacity(0);
progressIndicator.setProgress(0);
}
}
};
}
示例15: showPopup
import javafx.animation.Timeline; //導入方法依賴的package包/類
protected void showPopup() {
init();
isShowing = true;
VBox popupLayout = new VBox();
popupLayout.setSpacing(10);
popupLayout.setPadding(new Insets(10, 10, 10, 10));
StackPane popupContent = new StackPane();
popupContent.setPrefSize(width, height);
popupContent.getStyleClass().add("notification");
popupContent.getChildren().addAll(popupLayout);
popup = new Popup();
popup.setX(getX());
popup.setY(getY());
popup.getContent().add(popupContent);
popup.addEventHandler(MouseEvent.MOUSE_PRESSED, new WeakEventHandler<>(event -> {
fireNotificationEvent(new NotificationEvent(this, popup, NotificationEvent.NOTIFICATION_PRESSED));
hidePopUp();
}));
popups.add(popup);
// Add a timeline for popup fade out
KeyValue fadeOutBegin = new KeyValue(popup.opacityProperty(), 1.0);
KeyValue fadeOutEnd = new KeyValue(popup.opacityProperty(), 0.0);
KeyFrame kfBegin = new KeyFrame(Duration.ZERO, fadeOutBegin);
KeyFrame kfEnd = new KeyFrame(popupAnimationTime, fadeOutEnd);
timeline = new Timeline(kfBegin, kfEnd);
timeline.setDelay(popupLifetime);
timeline.setOnFinished(actionEvent -> Platform.runLater(() -> {
hidePopUp();
}));
if (stage.isShowing()) {
stage.toFront();
} else {
stage.show();
}
popup.show(stage);
fireNotificationEvent(new NotificationEvent(this, popup, NotificationEvent.SHOW_NOTIFICATION));
timeline.play();
}