本文整理了Java中javafx.animation.Timeline
类的一些代码示例,展示了Timeline
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Timeline
类的具体详情如下:
包路径:javafx.animation.Timeline
类名称:Timeline
暂无
代码示例来源:origin: jfoenixadmin/JFoenix
@Override
public void start(Stage stage) throws Exception {
final VBox pane = new VBox();
pane.setSpacing(30);
pane.setStyle("-fx-background-color:WHITE");
jfxBarInf.setProgress(-1.0f);
Timeline timeline = new Timeline(
new KeyFrame(
Duration.ZERO,
new KeyValue(bar.progressProperty(), 0),
new KeyValue(jfxBar.secondaryProgressProperty(), 0),
new KeyValue(jfxBar.progressProperty(), 0)),
new KeyFrame(
Duration.seconds(1),
new KeyValue(jfxBar.secondaryProgressProperty(), 1)),
new KeyValue(jfxBar.progressProperty(), 1)));
timeline.setCycleCount(Timeline.INDEFINITE);
timeline.play();
pane.getChildren().addAll(bar, jfxBar, cssBar, jfxBarInf);
代码示例来源:origin: jfoenixadmin/JFoenix
@Override
public <U> void setViewContext(ViewContext<U> context) {
updatePlaceholder(context.getRootNode());
if (animation != null) {
animation.stop();
}
animation = new Timeline();
animation.getKeyFrames().addAll(animationProducer.apply(this));
animation.getKeyFrames().add(new KeyFrame(duration, (e) -> clearPlaceholder()));
animation.play();
}
代码示例来源:origin: jfoenixadmin/JFoenix
KeyFrame[] greenFrame = getKeyFrames(1350, 4.2, initialColor == null ? greenColor : initialColor);
KeyFrame endingFrame = new KeyFrame(Duration.seconds(5.6),
new KeyValue(arc.lengthProperty(), 5, Interpolator.LINEAR),
new KeyValue(arc.startAngleProperty(),
timeline.stop();
timeline.getKeyFrames().clear();
timeline = new Timeline(blueFrame[0],
blueFrame[1],
blueFrame[2],
greenFrame[3],
endingFrame);
timeline.setCycleCount(Timeline.INDEFINITE);
timeline.setDelay(Duration.ZERO);
timeline.playFromStart();
代码示例来源:origin: stackoverflow.com
Timeline fiveSecondsWonder = new Timeline(new KeyFrame(Duration.seconds(5), new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("this is called every 5 seconds on UI thread");
}
}));
fiveSecondsWonder.setCycleCount(Timeline.INDEFINITE);
fiveSecondsWonder.play();
代码示例来源:origin: jfoenixadmin/JFoenix
/**
* Animates the list to show/hide the nodes.
*/
public void animateList() {
expanded = !expanded;
if (animateTimeline.getStatus() == Status.RUNNING) {
animateTimeline.stop();
}
animateTimeline.getKeyFrames().clear();
createAnimation(expanded, animateTimeline);
animateTimeline.play();
}
代码示例来源:origin: jfoenixadmin/JFoenix
private void clearAnimation() {
if (timeline != null) {
timeline.stop();
timeline.getKeyFrames().clear();
timeline = null;
}
}
}
代码示例来源:origin: stackoverflow.com
public class Main extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
IntegerProperty letters= new SimpleIntegerProperty(0);
Label label = new Label();
Button animate = new Button("animate");
letters.addListener((a, b, c) -> {
label.setText("animate".substring(0, c.intValue()));
});
animate.setOnAction((e)->{
Timeline timeline = new Timeline();
KeyValue kv = new KeyValue(letters, "animate".length());
KeyFrame kf = new KeyFrame(Duration.seconds(3), kv);
timeline.getKeyFrames().add(kf);
timeline.play();
});
BorderPane pane = new BorderPane(label, null, null, animate, null);
primaryStage.setScene(new Scene(pane, 300,300));
primaryStage.show();
}
}
代码示例来源:origin: stackoverflow.com
public void start(Stage primaryStage)throws Exception{
////////////////////Basic FX stuff
Canvas theCanvas = new Canvas(900,900);
StackPane theLayout = new StackPane();
theLayout.getChildren().add(theCanvas);
Scene theScene = new Scene(theLayout,900,900);
primaryStage.setScene(theScene);
primaryStage.show();
///////////////////////
/////Drawing an X
///////////////////////
GraphicsContext gc = theCanvas.getGraphicsContext2D();
Timeline timeline = new Timeline(
new KeyFrame(Duration.seconds(1), e -> gc.strokeLine(0,0,200,200)),
new KeyFrame(Duration.seconds(2), e -> gc.strokeLine(200,0,0,200))
);
timeline.play();
/////////////////////////////
}
代码示例来源:origin: stackoverflow.com
bar.setPrefSize(200, 24);
Timeline task = new Timeline(
new KeyFrame(
Duration.ZERO,
Button button = new Button("Go!");
button.setOnAction(new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent actionEvent) {
task.playFromStart();
VBox layout = new VBox(10);
layout.getChildren().setAll(
bar,
button
);
layout.setPadding(new Insets(10));
layout.setAlignment(Pos.CENTER);
);
stage.setScene(new Scene(layout));
stage.show();
代码示例来源:origin: stackoverflow.com
content.setVisible(false);
stage.setScene(scene);
stage.show();
Label label = new Label("The overlaid text is clear and the background below is frosty.");
slideIn.setOnFinished(e -> content.setVisible(true));
slideOut.stop();
slideIn.play();
});
slideIn.stop();
slideOut.play();
content.setVisible(false);
});
slideOut.stop();
slideIn.play();
} else {
slideIn.stop();
slideOut.play();
content.setVisible(false);
frostView.setClip(clipShape);
代码示例来源:origin: stackoverflow.com
final Label status = new Label("Loading");
final Timeline timeline = new Timeline(
new KeyFrame(Duration.ZERO, new EventHandler() {
@Override public void handle(Event event) {
String statusText = status.getText();
status.setText(
("Loading . . .".equals(statusText))
? "Loading ."
new KeyFrame(Duration.millis(1000))
);
timeline.setCycleCount(Timeline.INDEFINITE);
VBox layout = new VBox();
layout.getChildren().addAll(status);
layout.setStyle("-fx-background-color: cornsilk; -fx-padding: 10;");
stage.setScene(new Scene(layout, 50, 35));
stage.show();
timeline.play();
代码示例来源:origin: stackoverflow.com
public void start(Stage primaryStage) {
Label nome = new Label("Hello");
Timeline animation = new Timeline(
new KeyFrame(Duration.millis(1000),
event -> nome.setStyle("-fx-background-color: red;")),
new KeyFrame(Duration.millis(1500),
event -> nome.setStyle("-fx-background-color: black")));
animation.setCycleCount(Animation.INDEFINITE);
animation.play();
Button button = new Button();
button.setOnAction(event -> {
if (animation.getStatus() == Animation.Status.RUNNING) {
animation.stop();
} else {
animation.play();
button.textProperty().bind(Bindings
.when(animation.statusProperty().isEqualTo(Animation.Status.RUNNING))
.then("Stop")
.otherwise("Start"));
代码示例来源:origin: stackoverflow.com
@Override
public void start(Stage primaryStage) {
StackPane root = new StackPane();
Label label = new Label("Animated gradient");
root.getChildren().add(label);
label.getStyleClass().add("animated-gradient");
Scene scene = new Scene(root,400,400);
scene.getStylesheets().add(getClass().getResource("animated-gradient.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
});
timeline.setAutoReverse(true);
timeline.setCycleCount(Animation.INDEFINITE);
timeline.play();
代码示例来源:origin: stackoverflow.com
setMinSize(600, 600);
setStyle("-fx-border-color: blue;");
Label count = new Label();
count.textProperty().bind(Bindings.convert(frame));
getChildren().add(count);
count.setMouseTransparent(true);
Timeline t = new Timeline(new KeyFrame(Duration.millis(100), new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent event) {
frame.set(frame.get() + 1);
t.setCycleCount(Timeline.INDEFINITE);
t.play();
public static void main(String[] args) { launch(args); }
@Override public void start(Stage stage) {
stage.setScene(new Scene(new Test()));
stage.show();
代码示例来源:origin: stackoverflow.com
final DoubleProperty percentOfTimeUsed = new SimpleDoubleProperty(0);
final Timeline timer =
new Timeline(
new KeyFrame(
Duration.ZERO, new KeyValue(percentOfTimeUsed, 0)),
root.setTop(progressBar);
Button answer = new Button("Answer");
answer.setOnAction(ae -> restart());// the on answer handler
Button skip = new Button("Skip");
skip.setOnAction(ae -> restart());// the skip question handler
new Label("Your Question"), new TextField("The answer"), answer, skip);
root.setCenter(mainContent);
timer.setOnFinished(ae -> restart());// the end of timer handler
primaryStage.setScene(new Scene(root));
primaryStage.show();
void restart() { timer.stop(); timer.playFromStart(); }
void pause() { timer.pause(); }
void resume() { timer.play(); }
代码示例来源:origin: stackoverflow.com
private final IntegerProperty count = new SimpleIntegerProperty(TOTALTIME);
private final Label timerLabel = new Label();
private final Button btn = new Button("Start countdown");
timerLabel.textProperty().bind(count.asString());
timerLabel.setVisible(false);
final Timeline timeline = new Timeline();
timeline.setCycleCount(TOTALTIME);
KeyFrame keyFrame = new KeyFrame(Duration.seconds(1), e->count.set(count.get()-1));
timeline.getKeyFrames().add(keyFrame);
timeline.setOnFinished(e->handleFinish());
btn.setOnAction(e->{
btn.setDisable(true);
timerLabel.setVisible(true);
timeline.playFromStart();
});
Scene scene = new Scene(root, 300, 250);
primaryStage.setScene(scene);
primaryStage.show();
代码示例来源:origin: stackoverflow.com
@Override
public void start(Stage stage) {
Rectangle box = new Rectangle(0, 0, 50, 50);
KeyValue one = new KeyValue(box.xProperty(), 125);
KeyValue two = new KeyValue(box.yProperty(), 100);
KeyValue three = new KeyValue(box.xProperty(), 125);
KeyValue four = new KeyValue(box.yProperty(), 100);
KeyValue five = new KeyValue(box.xProperty(), 250);
KeyValue six = new KeyValue(box.yProperty(), 0);
KeyFrame frame = new KeyFrame(Duration.millis(3000), one, two);
KeyFrame frametwo = new KeyFrame(Duration.millis(8000), three, four);
KeyFrame framethree = new KeyFrame(Duration.millis(11000), five, six, new KeyValue(box.rotateProperty(), 360d * 11000d / 2000d, Interpolator.LINEAR));
Timeline timeline = new Timeline();
timeline.getKeyFrames().addAll(frame, frametwo, framethree);
timeline.play();
Group root = new Group();
root.getChildren().addAll(box);
Scene scene = new Scene(root, 300, 250);
stage.setScene(scene);
stage.show();
}
代码示例来源:origin: jfoenixadmin/JFoenix
groupNode.getChildren().setAll(((JFXListView<?>) newNode).getGroupnode(), dropIcon);
click.consume();
if (expandAnimation != null && expandAnimation.getStatus() == Status.RUNNING) {
expandAnimation.stop();
expandAnimation = new Timeline(new KeyFrame(Duration.millis(320),
expandAnimation.setOnFinished((finish) -> {
updateClipHeight(newHeight);
getListView().setPrefHeight(getListView().getHeight() + newAnimatedHeight);
});
expandAnimation.play();
});
new Timeline(new KeyFrame(Duration.millis(160),
new KeyValue(dropIcon.rotateProperty(),
90,
Interpolator.EASE_BOTH))).play();
} else {
new Timeline(new KeyFrame(Duration.millis(160),
new KeyValue(dropIcon.rotateProperty(),
0,
Interpolator.EASE_BOTH))).play();
代码示例来源:origin: stackoverflow.com
Label label = new Label("Bla bla bla bla");
shadow.setSpread(0.75);
Timeline shadowAnimation = new Timeline(
new KeyFrame(Duration.ZERO, new KeyValue(shadow.radiusProperty(), 0d)),
new KeyFrame(Duration.seconds(0.15), new KeyValue(shadow.radiusProperty(), 20d)));
shadowAnimation.setAutoReverse(true);
shadowAnimation.setCycleCount(2);
Button btn = new Button("flash");
btn.setOnAction((ActionEvent event) -> {
Node target = label;
target.setEffect(shadow);
shadowAnimation.setOnFinished(evt -> target.setEffect(null));
shadowAnimation.play();
});
primaryStage.setScene(scene);
primaryStage.show();
代码示例来源:origin: stackoverflow.com
label.setStyle(String.format("-fx-padding: 5px; -fx-background-radius: 5px; -fx-background-color: lightblue;"));
label.setStyle(String.format("-fx-padding: 5px; -fx-background-radius: 5px; -fx-background-color: rgba(255, 0, 0, %f)", newValue.doubleValue()));
final Timeline flashAnimation = new Timeline(
new KeyFrame(Duration.ZERO, new KeyValue(opacity, 1)),
new KeyFrame(Duration.millis(500), new KeyValue(opacity, 0)));
flashAnimation.setCycleCount(Animation.INDEFINITE);
flashAnimation.setAutoReverse(true);
label.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override public void handle(MouseEvent t) {
if (Animation.Status.STOPPED.equals(flashAnimation.getStatus())) {
flashAnimation.play();
} else {
flashAnimation.stop();
label.setStyle(String.format("-fx-padding: 5px; -fx-background-radius: 5px; -fx-background-color: lightblue;"));
stage.setScene(scene);
stage.show();
内容来源于网络,如有侵权,请联系作者删除!