Example usage for javafx.util Duration seconds

List of usage examples for javafx.util Duration seconds

Introduction

In this page you can find the example usage for javafx.util Duration seconds.

Prototype

public static Duration seconds(double s) 

Source Link

Document

Factory method that returns a Duration instance representing the specified number of seconds.

Usage

From source file:Main.java

private void addBouncyBall(final Scene scene) {
    final Circle ball = new Circle(100, 100, 20);

    final Group root = (Group) scene.getRoot();
    root.getChildren().add(ball);//w  w  w .  j a va 2 s  .c o  m

    Timeline tl = new Timeline();
    tl.setCycleCount(Animation.INDEFINITE);
    KeyFrame moveBall = new KeyFrame(Duration.seconds(.0200), new EventHandler<ActionEvent>() {

        public void handle(ActionEvent event) {

            double xMin = ball.getBoundsInParent().getMinX();
            double yMin = ball.getBoundsInParent().getMinY();
            double xMax = ball.getBoundsInParent().getMaxX();
            double yMax = ball.getBoundsInParent().getMaxY();

            if (xMin < 0 || xMax > scene.getWidth()) {
                dx = dx * -1;
            }
            if (yMin < 0 || yMax > scene.getHeight()) {
                dy = dy * -1;
            }

            ball.setTranslateX(ball.getTranslateX() + dx);
            ball.setTranslateY(ball.getTranslateY() + dy);

        }
    });

    tl.getKeyFrames().add(moveBall);
    tl.play();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    stage.setTitle("Rotations");
    stage.setScene(makeScene());/*from w ww  .ja va2  s .  co  m*/
    stage.show();
    TimelineBuilder.create().cycleCount(Timeline.INDEFINITE).keyFrames(
            new KeyFrame(Duration.seconds(0), new KeyValue(translateZForNode1, -100), new KeyValue(angle, 0)),
            new KeyFrame(Duration.seconds(2), new KeyValue(translateZForNode1, 100), new KeyValue(angle, 180)),
            new KeyFrame(Duration.seconds(4), new KeyValue(translateZForNode1, -100), new KeyValue(angle, 360))

    ).build().play();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Text msg = new Text("java2s.com");
    msg.setTextOrigin(VPos.TOP);/*from  ww  w .  j av  a2s .c o  m*/
    msg.setFont(Font.font(24));

    Pane root = new Pane(msg);
    root.setPrefSize(500, 70);
    Scene scene = new Scene(root);

    stage.setScene(scene);
    stage.setTitle("Scrolling Text");
    stage.show();

    double sceneWidth = scene.getWidth();
    double msgWidth = msg.getLayoutBounds().getWidth();

    KeyValue initKeyValue = new KeyValue(msg.translateXProperty(), sceneWidth);
    KeyFrame initFrame = new KeyFrame(Duration.ZERO, initKeyValue);

    KeyValue endKeyValue = new KeyValue(msg.translateXProperty(), -1.0 * msgWidth);
    KeyFrame endFrame = new KeyFrame(Duration.seconds(3), endKeyValue);

    Timeline timeline = new Timeline(initFrame, endFrame);

    timeline.setCycleCount(Timeline.INDEFINITE);
    timeline.play();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    DoubleProperty translate = new SimpleDoubleProperty();
    stage.setTitle("Hello JavaFX");
    Rectangle node1 = RectangleBuilder.create().x(0).y(0).width(10).height(10).fill(Color.RED).build();
    node1.translateXProperty().bind(translate);

    Parent parent = GroupBuilder.create().children(node1).translateX(250).translateY(250).build();
    stage.setScene(SceneBuilder.create().width(500).height(500).root(parent).build());
    stage.show();/*from  w  w w . ja  v a2  s.  c o  m*/

    TimelineBuilder.create().cycleCount(Timeline.INDEFINITE)
            .keyFrames(new KeyFrame(Duration.seconds(0), new KeyValue(translate, -50)),
                    new KeyFrame(Duration.seconds(2), new KeyValue(translate, 250)))
            .build().play();
}

From source file:pe.edu.system.jcmr.controlador.SplashController.java

public void start() {

    FadeTransition tt = new FadeTransition(Duration.seconds(16), stackMain);
    //         tt.setFromAngle(0);
    //         tt.setToAngle(360);
    //         tt.setAutoReverse(true);
    //         tt.setCycleCount(4);
    //         tt.setInterpolator(Interpolator.);
    //         tt.setAxis( Rotate.X_AXIS );

    tt.setAutoReverse(true);/*w  ww .ja v  a2  s  .  c om*/
    tt.setCycleCount(3);
    tt.setFromValue(1.0);
    tt.setToValue(0.0);

    RotateTransition rr = new RotateTransition(Duration.seconds(30), imgLogo);
    rr.setCycleCount(3);
    rr.setByAngle(360);

    //        rotator.setInterpolator(Interpolator.LINEAR);
    //                tt.setFromX( -(imgLogo.getFitWidth()) );
    //                tt.setToX( stackMain.getPrefWidth() );
    //                tt.setCycleCount( Timeline.INDEFINITE );
    //                tt.play();
    rr.play();
}

From source file:hd3gtv.as5kpc.Serverchannel.java

BackgroundWatcher createBackgroundWatcher() {
    BackgroundWatcher bw = new BackgroundWatcher();
    // bw.setDelay(Duration.seconds(1));
    bw.setRestartOnFailure(true);//from  w  w w  . j ava 2  s.c  o m
    bw.setMaximumFailureCount(10);
    bw.setPeriod(Duration.seconds(1));
    bw.setBackoffStrategy(service -> Duration.seconds(bw.getCurrentFailureCount() + 1));
    return bw;
}

From source file:spacetrader.controller.EncounterScreenController.java

/**
 * Initializes the controller class./*w w w .  ja va 2 s  . co m*/
 */
@Override
public void initialize(URL url, ResourceBundle rb) {
    minuteMatrix = new Array2DRowRealMatrix(MINUTE_ARROW);
    hourMatrix = new Array2DRowRealMatrix(HOUR_ARROW);
    context = canvas.getGraphicsContext2D();
    context.translate(375, 275);
    context.setFill(Color.CORNFLOWERBLUE);
    context.fillPolygon(minuteMatrix.getColumn(0), minuteMatrix.getColumn(1), 10);
    context.setFill(Color.MEDIUMAQUAMARINE);
    context.fillPolygon(hourMatrix.getColumn(0), hourMatrix.getColumn(1), 8);
    timeline = new Timeline();
    timeline.setCycleCount(Timeline.INDEFINITE);
    inCount = 0;
    upDown = true;
    KeyFrame frame = new KeyFrame(Duration.seconds(1.0 / 24), new EventHandler<ActionEvent>() {
        public void handle(ActionEvent event) {
            System.out.println(inCount);
            context.clearRect(-375, -275, 750, 550);
            context.setStroke(Color.rgb(0, outCount, 127 + outCount));
            context.setLineWidth(61);
            context.strokeOval(-230, -230, 460, 460);
            context.setStroke(Color.rgb(0, (outCount + 30) % 128, 127 + (outCount + 30) % 128));
            context.strokeOval(-290, -290, 580, 580);
            context.setStroke(Color.rgb(0, (outCount + 60) % 128, 127 + (outCount + 60) % 128));
            context.strokeOval(-350, -350, 700, 700);
            context.setStroke(Color.rgb(0, (outCount + 90) % 128, 127 + (outCount + 90) % 128));
            context.setLineWidth(100);
            context.strokeOval(-430, -430, 860, 860);

            context.setFill(new LinearGradient(-200, -200, 200, 200, false, CycleMethod.NO_CYCLE,
                    new Stop(0, Color.rgb(255, 255 - inCount, inCount)),
                    new Stop(1, Color.rgb(255 - inCount, 0, 255))));
            context.fillOval(-200, -200, 400, 400);
            minuteMatrix = minuteMatrix.multiply(minuteRotateMatrix);
            hourMatrix = hourMatrix.multiply(hourRotateMatrix);
            context.setFill(Color.CORNFLOWERBLUE);
            context.fillPolygon(minuteMatrix.getColumn(0), minuteMatrix.getColumn(1), 10);
            context.setFill(Color.MEDIUMAQUAMARINE);
            context.fillPolygon(hourMatrix.getColumn(0), hourMatrix.getColumn(1), 8);
            if (inCount % 20 < 10) {
                context.drawImage(
                        new Image(Paths.get("image/star.png").toUri().toString(), 360, 360, false, false), -180,
                        -180);
            } else {
                context.drawImage(
                        new Image(Paths.get("image/star.png").toUri().toString(), 300, 300, false, false), -150,
                        -150);
            }
            if (upDown) {
                inCount += 3;
                if (inCount >= 255) {
                    upDown = false;
                }
            } else {
                inCount -= 3;
                if (inCount <= 0) {
                    upDown = true;
                }
            }
            if (outCount >= 128) {
                outCount = 0;
            } else {
                outCount += 8;
            }
        }
    });
    timeline.getKeyFrames().add(frame);
    timeline.play();
}

From source file:ubicrypt.ui.ctrl.MainController.java

@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
    fxml = substringBefore(substringAfterLast(url.getFile(), "/"), ".fxml");
    log.debug("initialize fxml:{}, pgpservice:{}", fxml, pgpService);
    //file progress monitor
    progressEvents.subscribe(progress -> Platform.runLater(() -> {
        if (progress.isCompleted() || progress.isError()) {
            log.debug("progress completed");
            if (!filesInProgress.remove(progress)) {
                log.warn("progress not tracked. progress file:{}, element:{}",
                        progress.getProvenience().getFile());
            }/*from w ww  . j  a  va  2 s .  co m*/
            Timeline timeline = new Timeline(new KeyFrame(Duration.seconds(2), ae -> {
                footer.setText("");
                footer.setProgress(0D);
            }));
            timeline.play();
        } else {
            filesInProgress.add(progress);
        }
        if (filesInProgress.isEmpty()) {
            return;
        }
        footer.setVisible(true);
        filesInProgress.stream().findFirst().ifPresent(pr -> {
            String file = abbreviate(pr.getProvenience().getFile().getPath().getFileName().toString(), 30);
            String target = abbreviate(pr.getDirection() == ProgressFile.Direction.inbound
                    ? pr.getProvenience().getOrigin().toString()
                    : pr.getTarget().toString(), 30);
            String text = file + "  " + target;
            if (pr.getDirection() == ProgressFile.Direction.inbound) {
                text = target + "  " + file;
            }
            footer.setText(text);
            footer.setProgress((double) progress.getChunk() / pr.getProvenience().getFile().getSize());
        });
    }));
}

From source file:pe.edu.system.jcmr.controlador.SplashController.java

public void start2() {

    FadeTransition tt = new FadeTransition(Duration.seconds(16), stackMain);
    //         tt.setFromAngle(0);
    //         tt.setToAngle(360);
    //         tt.setAutoReverse(true);
    //         tt.setCycleCount(4);
    //         tt.setInterpolator(Interpolator.);
    //         tt.setAxis( Rotate.X_AXIS );

    tt.setAutoReverse(true);//from ww  w.j  av  a 2  s .c o m
    tt.setCycleCount(3);
    tt.setFromValue(1.0);
    tt.setToValue(0.0);

    RotateTransition rr = new RotateTransition(Duration.seconds(30), imgLogo2);
    rr.setCycleCount(3);
    rr.setByAngle(360);

    //        rotator.setInterpolator(Interpolator.LINEAR);
    //                tt.setFromX( -(imgLogo.getFitWidth()) );
    //                tt.setToX( stackMain.getPrefWidth() );
    //                tt.setCycleCount( Timeline.INDEFINITE );
    //                tt.play();
    rr.play();
}

From source file:org.noroomattheinn.visibletesla.LocationController.java

private Animation animateBlip() {
    final Circle core = new Circle(572, 360, 5);
    final Circle blip = new Circle(572, 360, 5);
    final Circle outline = new Circle(572, 360, 5);
    Duration blipTime = Duration.seconds(1.5);
    Duration interBlipTime = Duration.seconds(0.5);

    core.setFill(Color.BLUE);//from  w  ww .  j a  v  a  2 s .  c  om
    blip.setFill(Color.LIGHTBLUE);
    outline.setFill(Color.TRANSPARENT);
    outline.setStroke(Color.DARKBLUE);
    outline.setStrokeWidth(0.25);

    root.getChildren().addAll(blip, core, outline);

    FadeTransition fadeBlip = new FadeTransition(blipTime, blip);
    fadeBlip.setFromValue(0.8);
    fadeBlip.setToValue(0.0);

    ScaleTransition scaleBlip = new ScaleTransition(blipTime, blip);
    scaleBlip.setFromX(1);
    scaleBlip.setToX(4);
    scaleBlip.setFromY(1);
    scaleBlip.setToY(4);

    FadeTransition fadeOutline = new FadeTransition(blipTime, outline);
    fadeOutline.setFromValue(1.0);
    fadeOutline.setToValue(0.0);

    ScaleTransition scaleOutline = new ScaleTransition(blipTime, outline);
    scaleOutline.setFromX(1);
    scaleOutline.setToX(4);
    scaleOutline.setFromY(1);
    scaleOutline.setToY(4);

    SequentialTransition sequence = new SequentialTransition(
            new ParallelTransition(fadeBlip, scaleBlip, scaleOutline, fadeOutline),
            new PauseTransition(interBlipTime));
    sequence.setCycleCount(Timeline.INDEFINITE);
    sequence.setOnFinished(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent t) {
            core.setVisible(false);
            blip.setVisible(false);
            outline.setVisible(false);
        }
    });

    sequence.play();
    return sequence;
}