IDEA配置JDK15支持Java FX应用开发

1、到官网下载对应的Java FX   SDK开发包:https://gluonhq.com/products/javafx/

2、打开运行/调试设置    ====>配置虚拟机选项:

先引入lib包,指定lib文件夹

紧接着配置虚拟机选项:

--module-path “JavaFx SDK的lib文件夹路径C:\javafx-sdk-15.0.1\lib” --add-modules javafx.controls,javafx.fxml

这一步很重要,记得要选一下对应的版本模块

3、运行一下简单的示例项目

4、主要代码:


import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonBar;
import javafx.scene.control.ButtonType;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import javafx.stage.Window;

import javax.annotation.processing.Messager;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));  //加载布局文件
        primaryStage.setTitle("JavaFx入门");   //设置标题
        primaryStage.setScene(new Scene(root, 100, 100));  //初始化容器场景

        Button btn=new Button("点我");   //新建一个Button
        btn.setOnAction(this::handler);    //点击触发事件
        BorderPane bp=new BorderPane(); //设置容器
        bp.setCenter(btn);//将控件添加进容器
        Scene sc=new Scene(bp, 500, 500);  //设置场景,将容器添加进场景中并设置宽高
        primaryStage.setScene(sc);    //设置场景应用到初始化容器场景中

        primaryStage.show();   //显示场景页面
    }

    //点击事件
    public void handler(ActionEvent event) {
        f_alert_informationDialog("提示信息","你好呀。",null,null );
    }


    // 弹出一个信息对话框
    public void f_alert_informationDialog(String p_title,String p_header, String p_message, Window d_stage){
        Alert _alert = new Alert(Alert.AlertType.INFORMATION);
        _alert.setTitle(p_title);
        _alert.setHeaderText(p_header);
        _alert.setContentText(p_message);
        _alert.initOwner(d_stage);
        _alert.show();
    }

    //程序入口
    public static void main(String[] args) {
        launch(args);
    }
}

 

 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

人海中的海盗

你的打赏将是对我的激励

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值