1.下载javafx sdk
2.新建造一个java project项目
2.
 {
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.运行