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();
}
}

- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57