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 


成功!!!!!!!
 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值