• javafx02 Button


    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"));
    //      设置背景   Paint.valueOf("#8FBC8F15") 后面两位代表透明度
            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) {
    //                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
  • 相关阅读:
    最新Java JDK 21:全面解析与新特性探讨
    LeetCode题解:171. Excel 表列序号,哈希表,TypeScript,详细注释
    Matlab:创建分类数组
    首设农作物种业专区农民丰收节国际贸易促进会舌尖上进博会
    android 11 供第三方应用使用系统so库
    Qt5.14.2 大文件处理的Qt多线程黑科技
    【数据结构----树】校招笔试题总结
    HTTP静态文件服务器gohttpserver
    Android 反编译Apk (Mac)
    Tomcat实战之路
  • 原文地址:https://blog.csdn.net/Wantfly9951/article/details/130690164