Button
package org.example;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.*;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font;
import javafx.stage.Stage;
public class Launch7 extends Application {
public void start(Stage primaryStage) throws Exception {
Button b1=new Button();
b1.setText("按钮1");
b1.setLayoutX(100);
b1.setLayoutY(100);
b1.setPrefWidth(200);
b1.setPrefHeight(200);
b1.setFont(Font.font("仿宋",22));
b1.setTextFill(Paint.valueOf("#AFFFFF"));
BackgroundFill bgf=new BackgroundFill(Paint.valueOf("#8FBC8F15"),new CornerRadii(20),new Insets(10));
Background background = new Background(bgf);
b1.setBackground(background);
BorderStroke borderStroke = new BorderStroke(Paint.valueOf("#8F8F8F"),BorderStrokeStyle.SOLID,new CornerRadii(10),new BorderWidths(10));
Border border=new Border(borderStroke);
b1.setBorder(border);
b1.setStyle("-fx-background-color: #EE1213");
b1.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
Button button = (Button) event.getSource();
System.out.println("hello:"+button.getText());
}
});
Group root=new Group();
root.getChildren().add(b1);
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.setTitle("My Demo");
primaryStage.setHeight(800);
primaryStage.setWidth(800);
primaryStage.show();
}
}