首页 > 代码库 > 冯斌:JavaFx实例(十)“ControlCircleWithoutEventHandling”
冯斌:JavaFx实例(十)“ControlCircleWithoutEventHandling”
实例(十)与实例(十一)阐述了怎样给按钮添加事件句柄,实例(十)是未添加句柄前的效果,实例(十一)是添加句柄后的效果。
本实例代码如下:
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
public class ControlCircleWithoutEventHandling extends Application {
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
StackPane pane = new StackPane();
Circle circle = new Circle(50);
circle.setStroke(Color.BLACK);
circle.setFill(Color.WHITE);
pane.getChildren().add(circle);
HBox hBox = new HBox();
hBox.setSpacing(10);
hBox.setAlignment(Pos.CENTER);
Button btEnlarge = new Button("Enlarge");
Button btShrink = new Button("Shrink");
hBox.getChildren().add(btEnlarge);
hBox.getChildren().add(btShrink);
BorderPane borderPane = new BorderPane();
borderPane.setCenter(pane);
borderPane.setBottom(hBox);
BorderPane.setAlignment(hBox, Pos.CENTER);
Scene scene = new Scene(borderPane,200,150);
primaryStage.setTitle("ControlCircle");
primaryStage.setScene(scene);
primaryStage.show();
}
}
运行结果如下:
本文出自 “冯斌的技术博客” 博客,请务必保留此出处http://fengbin8606.blog.51cto.com/8840305/1574982
冯斌:JavaFx实例(十)“ControlCircleWithoutEventHandling”