广州北大青鸟计算机职业培训学校
互联网技术培训、软件技术培训、大数据培训、云计算培训、数据分析培训信息网
当前位置:网站首页 > 软件教程 > Java技术 > 正文

惠州​分享JavaFX时间轴实例_北大青鸟IT学校

作者:邓华发布时间:2021-05-22分类:Java技术浏览:814


导读:前面给大家分享了JavaFX时间轴的知识,那么为了让大家更好地理解JavaFX时间轴,惠州北大青鸟老师给大家分享JavaFX时间轴的实例,希望对大家学习Java有帮助。

前面给大家分享了JavaFX时间轴的知识,那么为了让大家更好地理解JavaFX时间轴,惠州北大青鸟老师给大家分享JavaFX时间轴的实例,希望对大家学习Java有帮助。

实例

/*
* Copyright (c) 2011, 2012 Oracle and/or its affiliates.
* All rights reserved. Use is subject to license terms.
*
* This file is available and licensed under the following license:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
*  - Redistributions of source code must retain the above copyright
*    notice, this list of conditions and the following disclaimer.
*  - Redistributions in binary form must reproduce the above copyright
*    notice, this list of conditions and the following disclaimer in
*    the documentation and/or other materials provided with the distribution.
*  - Neither the name of Oracle nor the names of its
*    contributors may be used to endorse or promote products derived
*    from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*///package colorfulcircles;import javafx.animation.KeyFrame;import javafx.animation.KeyValue;import javafx.animation.Timeline;import javafx.application.Application;import javafx.scene.Group;import javafx.scene.Node;import javafx.scene.Scene;import javafx.scene.effect.BlendMode;import javafx.scene.effect.BoxBlur;import javafx.scene.paint.Color;import javafx.scene.paint.CycleMethod;import javafx.scene.paint.LinearGradient;import javafx.scene.paint.Stop;import javafx.scene.shape.Circle;import javafx.scene.shape.Rectangle;import javafx.scene.shape.StrokeType;import javafx.stage.Stage;import javafx.util.Duration;import static java.lang.Math.random;public class Main extends Application {    public static void main(String[] args) {
       launch(args);
   }

   @Override    public void start(Stage primaryStage) {
       Group root = new Group();
       Scene scene = new Scene(root, 800, 600, Color.BLACK);
       primaryStage.setScene(scene);
       Group circles = new Group();        for (int i = 0; i < 30; i++) {
           Circle circle = new Circle(150, Color.web("white", 0.05));
           circle.setStrokeType(StrokeType.OUTSIDE);
           circle.setStroke(Color.web("white", 0.16));
           circle.setStrokeWidth(4);
           circles.getChildren().add(circle);
       }
       Rectangle colors = new Rectangle(scene.getWidth(), scene.getHeight(),                new LinearGradient(0f, 1f, 1f, 0f, true, CycleMethod.NO_CYCLE, new Stop[]{                    new Stop(0, Color.web("#f8bd55")),                    new Stop(0.14, Color.web("#c0fe56")),                    new Stop(0.28, Color.web("#5dfbc1")),                    new Stop(0.43, Color.web("#64c2f8")),                    new Stop(0.57, Color.web("#be4af7")),                    new Stop(0.71, Color.web("#ed5fc2")),                    new Stop(0.85, Color.web("#ef504c")),                    new Stop(1, Color.web("#f2660f")),}));
       Group blendModeGroup =                new Group(new Group(new Rectangle(scene.getWidth(), scene.getHeight(),
               Color.BLACK), circles), colors);
       colors.setBlendMode(BlendMode.OVERLAY);
       root.getChildren().add(blendModeGroup);
       circles.setEffect(new BoxBlur(10, 10, 3));
       Timeline timeline = new Timeline();        for (Node circle : circles.getChildren()) {
           timeline.getKeyFrames().addAll(                    new KeyFrame(Duration.ZERO, // set start position at 0                    new KeyValue(circle.translateXProperty(), random() * 800),                    new KeyValue(circle.translateYProperty(), random() * 600)),                    new KeyFrame(new Duration(40000), // set end position at 40s                    new KeyValue(circle.translateXProperty(), random() * 800),                    new KeyValue(circle.translateYProperty(), random() * 600)));
       }        // play 40s of animation        timeline.play();

       primaryStage.show();
   }
}

上面的代码生成以下结果。

JavaFX时间轴动画1.png

更多Java资讯关注网站动态,或者来惠州北大青鸟新方舟校区了解一下。

标签:惠州计算机JAVA软件开发惠州计算机Java软件开发惠州计算机JAVA培训惠州计算机JAVA软件开发学校惠州计算机Java软件开发培训JAVAJava软件开发北大青鸟IT计算机学校北大青鸟IT软件学校北大青鸟IT学校


Java技术排行
标签列表
网站分类
文章归档
最近发表