网站:https://chat.jinshutuan.com/

这个网站号称永久免费,大家可以保存 有需要的时候可以用上。

下面是简单网站使用

正在为您搜索:Java、樱花掉落、代码

下面是一个简单的 Java 樱花掉落的代码,使用 JavaFX 来实现动画效果:

javaCopy Codeimport javafx.animation.Animation;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;
import javafx.util.Duration;

import java.util.Random;

public class CherryBlossom extends Application {

    private static final int WIDTH = 1000;
    private static final int HEIGHT = 600;
    private static final Image CHERRY_BLOSSOM_IMAGE = new Image("https://i.imgur.com/QOuOQ1s.png");

    private Group rootNode = new Group();
    private Random random = new Random();

    public void start(Stage stage) {
        Scene scene = new Scene(rootNode, WIDTH, HEIGHT);

        Timeline timeline = new Timeline(new KeyFrame(Duration.millis(50), event -> {
            ImageView imageView = new ImageView(CHERRY_BLOSSOM_IMAGE);
            imageView.setX(random.nextInt(WIDTH));
            imageView.setY(-CHERRY_BLOSSOM_IMAGE.getHeight());
            rootNode.getChildren().add(imageView);

            Animation animation = new Timeline(
                    new KeyFrame(Duration.ZERO, e -> imageView.setRotate(0)),
                    new KeyFrame(Duration.seconds(2), e -> imageView.setRotate(random.nextInt(360)))
            );
            animation.setCycleCount(Animation.INDEFINITE);
            animation.play();

            imageView.translateYProperty().addListener((observable, oldValue, newValue) -> {
                if (newValue.doubleValue() >= HEIGHT) {
                    rootNode.getChildren().remove(imageView);
                }
            });
            imageView.setOpacity(0.8);
            imageView.setFitWidth(CHERRY_BLOSSOM_IMAGE.getWidth() / 2);
            imageView.setFitHeight(CHERRY_BLOSSOM_IMAGE.getHeight() / 2);
        }));
        timeline.setCycleCount(Animation.INDEFINITE);
        timeline.play();

        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

这段代码会在窗口中不断地生成樱花图片并让其从上往下落,并增加旋转和透明度的效果。