eclipse使用javafx

1.下载javafx sdk

2.新建造一个java project项目

2.

![请添加图片描述](https://i-blog.csdnimg.cn/direct/90aa50557c9443a988b87d3cf96f5289.png

3JavafFxMain代码

bash 复制代码
package LA;

import static javafx.application.Application.launch;

public class JavafFxMain {

    public static void main(String[] args) {
        launch(JavaFxApp.class,args);
    }
}

4.JavaFxApp代码

bash 复制代码
package LA;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class JavaFxApp extends Application {
    @Override
    public void start(Stage primaryStage) {
        // 创建标签
        Label label = new Label("Hello, JavaFX!");

        // 创建按钮
        Button button = new Button("Click me!");

        // 当按钮被点击时改变标签的内容
        button.setOnAction(e -> label.setText("Button clicked!"));

        // 创建布局
        VBox vbox = new VBox(10, label, button);
        vbox.setStyle("-fx-padding: 10; -fx-alignment: center;");

        // 创建场景
        Scene scene = new Scene(vbox, 300, 200);

        // 设置主舞台
        primaryStage.setTitle("JavaFX Example");
        primaryStage.setScene(scene);
        primaryStage.show();
    }
    public static void main(String[] args) {
        launch(args);
    }
}

5.module-info.java代码

bash 复制代码
module EclipseJavaFx {
	requires javafx.graphics;
	requires javafx.controls;
	exports LA;
}

6.导入sdk的依赖

7.运行

相关推荐
韩仔搭建44 分钟前
第二章:安卓端启动流程详解与疑难杂症调试手册
android·ui·娱乐
A-花开堪折1 小时前
Android7 Input(七)App与input系统服务建立连接
android
冰糖葫芦三剑客1 小时前
Android 自定义悬浮拖动吸附按钮
android
吃汉堡吃到饱1 小时前
【Android】从Choreographer到UI渲染(二)
android·ui
微信公众号:AI创造财富1 小时前
显示的图标跟UI界面对应不上。
android·ui
aningxiaoxixi1 小时前
安卓 Audio Stream 类型
android
找不到、了1 小时前
Spring-Beans的生命周期的介绍
java·开发语言·spring
奔跑吧 android2 小时前
【android bluetooth 协议分析 01】【HCI 层介绍 3】【NUMBER_OF_COMPLETED_PACKETS 事件介绍】
android·bluetooth·hci·bt·gd·aosp13
caihuayuan42 小时前
React Native 0.68 安装react-native-picker报错:找不到compile
java·大数据·sql·spring·课程设计
爱编程的鱼2 小时前
C#接口(Interface)全方位讲解:定义、特性、应用与实践
java·前端·c#