Java黑皮书15.2(旋转矩形)

Java黑皮书15.2(旋转矩形),第1张

Java黑皮书15.2(旋转矩形) Java黑皮书15.2(旋转矩形)
package sample;

import javafx.application.*;
import javafx.stage.*;
import javafx.scene.*;
import javafx.scene.layout.*;
import javafx.scene.paint.*;
import javafx.scene.shape.*;
import javafx.scene.control.*;
import javafx.geometry.*;

public class Main extends Application {
    public static void main(String[] args) {
        launch(args);
    }

    private double angle = 0;

    @Override
    public void start(Stage primaryStage) {
        VBox vBox = new VBox(10);
        vBox.setPadding(new Insets(40, 40, 40, 40));
        Rectangle re = new Rectangle(100, 100, 100, 200);
        re.setFill(Color.WHITE);
        re.setStroke(Color.BLACK);
        Button btRotate = new Button("旋转");
        vBox.getChildren().addAll(re, btRotate);
        vBox.setAlignment(Pos.CENTER);
        btRotate.setOnAction(e -> {
            change(re);
        });
        Scene scene = new Scene(vBox, 600, 600);
        primaryStage.setTitle("旋转矩形");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public void change(Rectangle re) {
        angle += 15;
        re.setRotate(angle);
    }
}
运行结果

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5661255.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存