IDEA创建JAVAFX并打包成exe - Go语言中文社区

IDEA创建JAVAFX并打包成exe


IDEA版本2017
创建项目
这里写图片描述
在xml页面拖入button跟label,命名为btn1和lab1
这里写图片描述

sample.fxml配置如下一定注意加上fx:controller=”sample.Controller”

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.Pane?>

<AnchorPane fx:controller="sample.Controller" prefHeight="338.0" prefWidth="633.0" xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1">

   <children>
      <Pane layoutX="14.0" layoutY="14.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="216.0" prefWidth="480.0">
         <children>
            <Button fx:id="btn1" layoutX="36.0" layoutY="79.0" mnemonicParsing="false" onAction="#onButtonClick" rotate="16.7" text="Button1" />
            <Label fx:id="lab1" layoutX="178.0" layoutY="110.0" text="Label" />
         </children>
      </Pane>
   </children>
</AnchorPane>

Controller.class代码如下

package sample;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.event.ActionEvent;
import javafx.scene.control.Label;
import javafx.scene.control.Alert;


public class Controller {


    @FXML
    private Button btn1;
    @FXML
    private Label lab1;

    @FXML
    public void onButtonClick(ActionEvent event) {
        lab1.setText("HelloWorld");
        Alert _alert = new Alert(Alert.AlertType.INFORMATION);
        _alert.setTitle("信息");
        _alert.setHeaderText("11111111");
        _alert.setContentText("aaaaaaaa");

        _alert.show();
    }
}

Main.class如下

package sample;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;

import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{

        Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
        primaryStage.setTitle("Hello World");
        primaryStage.setScene(new Scene(root, 300, 275));
        primaryStage.show();
    }


    public static void main(String[] args) {

        launch(args);
    }
}

运行结果
这里写图片描述

下面开始打包成exe
这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述

成功!!!!!!!

版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/wangyinlon/article/details/79247606
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2021-05-19 02:25:57
  • 阅读 ( 666 )
  • 分类:

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢