zoukankan      html  css  js  c++  java
  • 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 


    成功!!!!!!!
     

  • 相关阅读:
    JavaScript面向对象精要(一)
    触摸事件
    移动端触摸事件介绍
    总结js常用函数和常用技巧(持续更新)
    JavaScript 常用函数总结
    windows环境下安装vue+webpack的开发环境
    js面向对象,多种创建对象方法!
    javascript遍历算法与技巧
    前端工作面试问题--摘取自github
    c++刷题(27/100)反转单项链表,链表的倒数第k个
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13317314.html
Copyright © 2011-2022 走看看