Java Code Examples for javafx.util.Duration#seconds()

The following examples show how to use javafx.util.Duration#seconds() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RubikView.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public RubikView() {
    
    rubik = new Rubik();
    setCenter(rubik.getSubScene());
    
    timer = new Timeline(
        new KeyFrame(Duration.ZERO, 
            e -> clock.set(LocalTime.now().minusNanos(time.toNanoOfDay()).format(fmt))),
        new KeyFrame(Duration.seconds(1)));
    
    timer.setCycleCount(Animation.INDEFINITE);
    timeLabel = new Label();
    timeLabel.setStyle("-fx-text-fill: white; -fx-font-size: 0.9em;");
    timeLabel.textProperty().bind(clock);
    
    rubik.isSolved().addListener((ov,b,b1)->{
        if(b1){
            timer.stop();
            MobileApplication.getInstance().showMessage("Solved in " + (rubik.getCount().get() + 1) + " movements!");
        }
    });
    
    getStylesheets().add(RubikView.class.getResource("rubik.css").toExternalForm());
    addEventHandler(MouseEvent.ANY, rubik.eventHandler);
}
 
Example 2
Source File: SpinnerController.java    From JFoenix with Apache License 2.0 6 votes vote down vote up
@PostConstruct
public void init() {
    Timeline timeline = new Timeline(
        new KeyFrame(
            Duration.ZERO,
            new KeyValue(blueSpinner.progressProperty(), 0),
            new KeyValue(greenSpinner.progressProperty(), 0)
        ),
        new KeyFrame(
            Duration.seconds(0.5),
            new KeyValue(greenSpinner.progressProperty(), 0.5)
        ),
        new KeyFrame(
            Duration.seconds(2),
            new KeyValue(blueSpinner.progressProperty(), 1),
            new KeyValue(greenSpinner.progressProperty(), 1)
        )
    );
    timeline.setCycleCount(Timeline.INDEFINITE);
    timeline.play();
}
 
Example 3
Source File: SpriteView.java    From training with MIT License 6 votes vote down vote up
public void moveTo(Main.Location loc) {
    walking = new Timeline(Animation.INDEFINITE,
        new KeyFrame(Duration.seconds(.001), new KeyValue(direction, location.getValue().directionTo(loc))),
        new KeyFrame(Duration.seconds(.002), new KeyValue(location, loc)),
        new KeyFrame(Duration.seconds(1), new KeyValue(translateXProperty(), loc.getX() * Main.CELL_SIZE)),
        new KeyFrame(Duration.seconds(1), new KeyValue(translateYProperty(), loc.getY() * Main.CELL_SIZE)),
        new KeyFrame(Duration.seconds(.25), new KeyValue(frame, 0)),
        new KeyFrame(Duration.seconds(.5), new KeyValue(frame, 1)),
        new KeyFrame(Duration.seconds(.75), new KeyValue(frame, 2)),
        new KeyFrame(Duration.seconds(1), new KeyValue(frame, 1))
    );
    walking.setOnFinished(e -> {
        if (arrivalHandler != null) {
            arrivalHandler.handle(e);
        }
    });
    Application.invokeLater(walking::play);
}
 
Example 4
Source File: JFXSpinnerSkin.java    From JFoenix with Apache License 2.0 6 votes vote down vote up
private KeyFrame[] getKeyFrames(double angle, double duration, Paint color) {
    KeyFrame[] frames = new KeyFrame[4];
    frames[0] = new KeyFrame(Duration.seconds(duration),
        new KeyValue(arc.lengthProperty(), 5, Interpolator.LINEAR),
        new KeyValue(arc.startAngleProperty(),
            angle + 45 + control.getStartingAngle(),
            Interpolator.LINEAR));
    frames[1] = new KeyFrame(Duration.seconds(duration + 0.4),
        new KeyValue(arc.lengthProperty(), 250, Interpolator.LINEAR),
        new KeyValue(arc.startAngleProperty(),
            angle + 90 + control.getStartingAngle(),
            Interpolator.LINEAR));
    frames[2] = new KeyFrame(Duration.seconds(duration + 0.7),
        new KeyValue(arc.lengthProperty(), 250, Interpolator.LINEAR),
        new KeyValue(arc.startAngleProperty(),
            angle + 135 + control.getStartingAngle(),
            Interpolator.LINEAR));
    frames[3] = new KeyFrame(Duration.seconds(duration + 1.1),
        new KeyValue(arc.lengthProperty(), 5, Interpolator.LINEAR),
        new KeyValue(arc.startAngleProperty(),
            angle + 435 + control.getStartingAngle(),
            Interpolator.LINEAR),
        new KeyValue(arc.strokeProperty(), color, Interpolator.EASE_BOTH));
    return frames;
}
 
Example 5
Source File: RandomMoveComponent.java    From FXGLGames with MIT License 5 votes vote down vote up
@Override
public void onUpdate(double tpf) {
    moveComponent.setMoveDirection(direction);

    if (moveTimer.elapsed(moveInterval)) {
        moveInterval = Duration.seconds(FXGLMath.random(0.25, 3.0));
        direction = FXGLMath.random(MoveDirection.values()).get();
        moveTimer.capture();
    }
}
 
Example 6
Source File: BossLevel1.java    From FXGLGames with MIT License 5 votes vote down vote up
@Override
public void onUpdate(double tpf) {
    if (attackTimer.elapsed(nextAttack)) {
        shoot();

        nextAttack = Duration.seconds(1);
        attackTimer.capture();
    }
}
 
Example 7
Source File: DockCommandsBox.java    From AnchorFX with GNU Lesser General Public License v3.0 5 votes vote down vote up
void notifyOpenAction() {
    RotateTransition rotate = new RotateTransition(Duration.seconds(0.2), menuButton.getGraphic());
    rotate.setToAngle(90);
    rotate.play();

    openAction.run();
}
 
Example 8
Source File: RandomMoveComponent.java    From FXGLGames with MIT License 5 votes vote down vote up
@Override
public void onUpdate(double tpf) {
    moveComponent.setMoveDirection(direction);

    if (moveTimer.elapsed(moveInterval)) {
        moveInterval = Duration.seconds(FXGLMath.random(0.25, 3.0));
        direction = FXGLMath.random(MoveDirection.values()).get();
        moveTimer.capture();
    }
}
 
Example 9
Source File: SpellTextArea.java    From Quelea with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Check the spelling on this text area - called internally to update state,
 * but can be fired externally also.
 * <p/>
 *
 * @param lastWord true if the last word should be included in the spell
 *                 check.
 */
public void updateSpelling(boolean lastWord) {
    spellingOkProperty.set(speller.checkText(getText(), lastWord));
    FadeTransition transition = new FadeTransition(Duration.seconds(0.2), warning);
    if (spellingOkProperty.get()) {
        transition.setFromValue(warning.getOpacity());
        transition.setToValue(0);
    } else {
        transition.setFromValue(warning.getOpacity());
        transition.setToValue(WARNING_OPACITY);
    }
    transition.play();
}
 
Example 10
Source File: CardRevealedToken.java    From metastone with GNU General Public License v2.0 5 votes vote down vote up
private void nextTransition(ActionEvent event) {
	FadeTransition animation = new FadeTransition(Duration.seconds(.6), cardToken);
	animation.setOnFinished(this::onComplete);
	animation.setFromValue(1);
	animation.setToValue(0);
	animation.play();
}
 
Example 11
Source File: FroggerApp.java    From FXTutorials with MIT License 5 votes vote down vote up
private void checkState() {
    for (Node car : cars) {
        if (car.getBoundsInParent().intersects(frog.getBoundsInParent())) {
            frog.setTranslateX(0);
            frog.setTranslateY(600 - 39);
            return;
        }
    }

    if (frog.getTranslateY() <= 0) {
        timer.stop();
        String win = "YOU WIN";

        HBox hBox = new HBox();
        hBox.setTranslateX(300);
        hBox.setTranslateY(250);
        root.getChildren().add(hBox);

        for (int i = 0; i < win.toCharArray().length; i++) {
            char letter = win.charAt(i);

            Text text = new Text(String.valueOf(letter));
            text.setFont(Font.font(48));
            text.setOpacity(0);

            hBox.getChildren().add(text);

            FadeTransition ft = new FadeTransition(Duration.seconds(0.66), text);
            ft.setToValue(1);
            ft.setDelay(Duration.seconds(i * 0.15));
            ft.play();
        }
    }
}
 
Example 12
Source File: MenuApp.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
/**
     * Ends the line animation
     */
    public void endLineAnimation() {
        ScaleTransition st = new ScaleTransition(Duration.seconds(.5), line);
        st.setToY(0);
        st.play();
//        st.setOnFinished(e -> clearLineItems());
//        clearLineItems();
    }
 
Example 13
Source File: BallComponent.java    From FXGLGames with MIT License 4 votes vote down vote up
public GrowEffect() {
    super(Duration.seconds(3));
}
 
Example 14
Source File: TimelineEventsSample.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
public TimelineEventsSample() {
    super(70,70);
    //create a circle with effect
    final Circle circle = new Circle(20,  Color.rgb(156,216,255));
    circle.setEffect(new Lighting());
    //create a text inside a circle
    final Text text = new Text (i.toString());
    text.setStroke(Color.BLACK);
    //create a layout for circle with text inside
    final StackPane stack = new StackPane();
    stack.getChildren().addAll(circle, text);
    stack.setLayoutX(30);
    stack.setLayoutY(30);

    //create a timeline for moving the circle

    timeline = new Timeline();
    timeline.setCycleCount(Timeline.INDEFINITE);
    timeline.setAutoReverse(true);

    //one can add a specific action when each frame is started. There are one or more frames during
    // executing one KeyFrame depending on set Interpolator.
    timer = new AnimationTimer() {
        @Override
        public void handle(long l) {
            text.setText(i.toString());
            i++;
        }

    };

    //create a keyValue with factory: scaling the circle 2times
    KeyValue keyValueX = new KeyValue(stack.scaleXProperty(), 2);
    KeyValue keyValueY = new KeyValue(stack.scaleYProperty(), 2);

    //create a keyFrame, the keyValue is reached at time 2s
    Duration duration = Duration.seconds(2);
    //one can add a specific action when the keyframe is reached
    EventHandler<ActionEvent> onFinished = new EventHandler<ActionEvent>() {
        public void handle(ActionEvent t) {
             stack.setTranslateX(java.lang.Math.random()*200-100);
             //reset counter
             i = 0;
        }
    };

    KeyFrame keyFrame = new KeyFrame(duration, onFinished , keyValueX, keyValueY);

    //add the keyframe to the timeline
    timeline.getKeyFrames().add(keyFrame);

    getChildren().add(stack);
}
 
Example 15
Source File: Simple3DSphereApp.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
public Parent createContent() throws Exception {

        Image dImage = new Image(Simple3DSphereApp.class.getResource("/maps/earth-d.jpg").toExternalForm());
        Image nImage = new Image(Simple3DSphereApp.class.getResource("/maps/earth-n.jpg").toExternalForm());
        Image sImage = new Image(Simple3DSphereApp.class.getResource("/maps/earth-s.jpg").toExternalForm());
        Image siImage = new Image(Simple3DSphereApp.class.getResource("/maps/earth-l.jpg").toExternalForm());

        material = new PhongMaterial();
        material.setDiffuseColor(Color.WHITE);
        material.diffuseMapProperty().bind(
                Bindings.when(diffuseMap).then(dImage).otherwise((Image) null));
        material.setSpecularColor(Color.TRANSPARENT);
        material.specularMapProperty().bind(
                Bindings.when(specularMap).then(sImage).otherwise((Image) null));
        material.bumpMapProperty().bind(
                Bindings.when(bumpMap).then(nImage).otherwise((Image) null));
        material.selfIlluminationMapProperty().bind(
                Bindings.when(selfIlluminationMap).then(siImage).otherwise((Image) null));

        earth = new Sphere(5);
        earth.setMaterial(material);
        earth.setRotationAxis(Rotate.Y_AXIS);


        // Create and position camera
        PerspectiveCamera camera = new PerspectiveCamera(true);
        camera.getTransforms().addAll(
                new Rotate(-20, Rotate.Y_AXIS),
                new Rotate(-20, Rotate.X_AXIS),
                new Translate(0, 0, -20));

        sun = new PointLight(Color.rgb(255, 243, 234));
        sun.translateXProperty().bind(sunDistance.multiply(-0.82));
        sun.translateYProperty().bind(sunDistance.multiply(-0.41));
        sun.translateZProperty().bind(sunDistance.multiply(-0.41));
        sun.lightOnProperty().bind(sunLight);

        AmbientLight ambient = new AmbientLight(Color.rgb(1, 1, 1));

        // Build the Scene Graph
        Group root = new Group();
        root.getChildren().add(camera);
        root.getChildren().add(earth);
        root.getChildren().add(sun);
        root.getChildren().add(ambient);

        RotateTransition rt = new RotateTransition(Duration.seconds(24), earth);
        rt.setByAngle(360);
        rt.setInterpolator(Interpolator.LINEAR);
        rt.setCycleCount(Animation.INDEFINITE);
        rt.play();

        // Use a SubScene
        SubScene subScene = new SubScene(root, 400, 300, true, SceneAntialiasing.BALANCED);
        subScene.setFill(Color.TRANSPARENT);
        subScene.setCamera(camera);

        return new Group(subScene);
    }
 
Example 16
Source File: BallComponent.java    From FXGLGames with MIT License 4 votes vote down vote up
public HighlightEffect() {
    super(Duration.seconds(0.05));
}
 
Example 17
Source File: Example3T.java    From Introduction-to-JavaFX-for-Game-Development with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void start(Stage theStage) 
{
    theStage.setTitle( "Timeline Example" );
    
    Group root = new Group();
    Scene theScene = new Scene( root );
    theStage.setScene( theScene );
    
    Canvas canvas = new Canvas( 512, 512 );
    root.getChildren().add( canvas );
    
    GraphicsContext gc = canvas.getGraphicsContext2D();
    
    Image earth = new Image( "earth.png" );
    Image sun   = new Image( "sun.png" );
    Image space = new Image( "space.png" );
    
    Timeline gameLoop = new Timeline();
    gameLoop.setCycleCount( Timeline.INDEFINITE );
    
    final long timeStart = System.currentTimeMillis();
    
    KeyFrame kf = new KeyFrame(
        Duration.seconds(0.017),                // 60 FPS
        new EventHandler<ActionEvent>()
        {
            public void handle(ActionEvent ae)
            {
                double t = (System.currentTimeMillis() - timeStart) / 1000.0; 
                            
                double x = 232 + 128 * Math.cos(t);
                double y = 232 + 128 * Math.sin(t);
                
                // Clear the canvas
                gc.clearRect(0, 0, 512,512);
                
                // background image clears canvas
                gc.drawImage( space, 0, 0 );
                gc.drawImage( earth, x, y );
                gc.drawImage( sun, 196, 196 );
            }
        });
    
    gameLoop.getKeyFrames().add( kf );
    gameLoop.play();
    
    theStage.show();
}
 
Example 18
Source File: ProgressBarDemo.java    From JFoenix with Apache License 2.0 4 votes vote down vote up
@Override
public void start(Stage stage) throws Exception {

    final VBox pane = new VBox();
    pane.setSpacing(30);
    pane.setStyle("-fx-background-color:WHITE");

    ProgressBar bar = new ProgressBar();
    bar.setPrefWidth(500);

    ProgressBar cssBar = new ProgressBar();
    cssBar.setPrefWidth(500);
    cssBar.setProgress(-1.0f);

    JFXProgressBar jfxBar = new JFXProgressBar();
    jfxBar.setPrefWidth(500);

    JFXProgressBar jfxBarInf = new JFXProgressBar();
    jfxBarInf.setPrefWidth(500);
    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 KeyFrame(
            Duration.seconds(2),
            new KeyValue(bar.progressProperty(), 1),
            new KeyValue(jfxBar.progressProperty(), 1)));

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

    pane.getChildren().addAll(bar, jfxBar, cssBar, jfxBarInf);

    StackPane main = new StackPane();
    main.getChildren().add(pane);
    main.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
    StackPane.setMargin(pane, new Insets(20, 0, 0, 20));

    final Scene scene = new Scene(main, 600, 200, Color.WHITE);
    scene.getStylesheets().add(ProgressBarDemo.class.getResource("/css/jfoenix-components.css").toExternalForm());
    stage.setTitle("JFX ProgressBar Demo ");
    stage.setScene(scene);
    stage.setResizable(false);
    stage.show();

}
 
Example 19
Source File: Main.java    From FXTutorials with MIT License 4 votes vote down vote up
public void show() {
    setVisible(true);
    TranslateTransition tt = new TranslateTransition(Duration.seconds(0.5), this);
    tt.setToX(0);
    tt.play();
}
 
Example 20
Source File: SearchBox.java    From phoenicis with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Constructor
 *
 * @param searchTerm The submitted search term
 */
public SearchBox(StringProperty searchTerm) {
    this(searchTerm, new SimpleObjectProperty<>(Duration.seconds(0.5)));
}