JAVA黑皮书课后练习题15章15.2

该程序创建了一个JavaFX应用,当点击Rotate按钮时,会将矩形顺时针旋转15度。矩形的初始尺寸为100x40,填充色为白色,边框色为黑色。应用使用BorderPane布局管理器,并设置了适当的内边距。
摘要由CSDN通过智能技术生成

15.2 (Rotate a rectangle) Write a program that rotates a rectangle 15 degrees right when the Rotate button is clicked, as shown in Figure 15.24b.

package section_15;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

public class _02 extends Application {
	public void start(Stage primaryStage) {
		Rectangle rectangle = new Rectangle();
		rectangle.setWidth(100);
		rectangle.setHeight(40);
		rectangle.setStroke(Color.BLACK);
		rectangle.setFill(Color.WHITE);
		Button btRotate = new Button("Rotate");

		btRotate.setOnAction(e -> rectangle.setRotate(rectangle.getRotate() + 15));

		BorderPane pane = new BorderPane();
		pane.setCenter(rectangle);
		pane.setBottom(btRotate);
		BorderPane.setAlignment(rectangle, Pos.CENTER);
		BorderPane.setAlignment(btRotate, Pos.CENTER);
		pane.setPadding(new Insets(5, 5, 5, 5));

		Scene scene = new Scene(pane, 200, 200);
		primaryStage.setTitle("_15_02");
		primaryStage.setScene(scene);
		primaryStage.show();
	}

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值