EasyCode(代码神器)

点击上方的终端研发部,右上角选择“设为星标

每日早8点半,技术文章准时送上

公众号后台回复“学习”,获取作者独家秘制精品资料

作者:范er_3dca
链接:https://www.jianshu.com/p/380d87df71e3

前言

前言

很多时候,我总会有一些莫名其妙的想法,但是光会后端就只能通过main函数调用来实现我的想法,这种实践手法就有点low,后来我学会了vue-cli构建前端工程,但这个工作量有点大,仅适合闲时较多的时候去做。这个时候我捡起了以前用过的javafx,它和swing其实也差不多,但是更方便,再加上以前我做过C#开发,有很多东西是互通的,减少了很多学习成本。

步骤说明

因为springboot的使用比spring方便太多了,这里我采用的基于springboot来构建javafx的工程,然后我采用的编译器是idea

步骤1

首先我们创建一个springboot项目(这个过程就跳过了,这个教程百度上很多的),然后创建后面要放代码的文件夹,方便后续代码管理,如下所示。

  • constant文件夹用于存放静态变量

  • controller用于存放页面控制器代码

  • model用于对象类

  • template这个是我这个项目中用

  • utils用于存放工具类

  • view用于存放自定义的展示页面控件

  • css用于存放静态的css文件,css是用来美化展示页面的,一个好看的页面对于一个桌面应用来说尤为重要

  • image用于存放静态图片资源

  • view用于存放fxml,相当于html,这里可以配置展示页面的各个空间的位置,大小,颜色什么的

步骤2

然后引入需要依赖的jar包

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.alibaba/druid -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.1.9</version>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>

        <!-- 这个必须要引入,是用来让javafx支持springboot的,必须要引入
        且这个jar的版本和springboot版本必须要对应,否则程序会报错 -->
        <dependency>
            <groupId>de.roskenet</groupId>
            <artifactId>springboot-javafx-support</artifactId>
            <version>2.1.6</version>
        </dependency>

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.30</version>
        </dependency>

    </dependencies>

    .....
步骤3

改造启动类,如下所示
这里说明一下,因为我需要用户手动配置数据库连接信息,所以我把DataSourceAutoConfiguration给移除了,不然会报错。

步骤4

到这里还有两个类没有交代MainView和InitializationView,前者是用于唤起主窗口的,后者是用于初始化页面加载的,你可以设置过场动画什么的

步骤5

编写主窗口控制器

步骤6

在view文件夹中创建fxml

然后在fxml中配置好对应的controller

步骤7

打包成exe的相关配置,这里它打完包之后就会把对应的java运行需要的jar都装进去,估计会有200M左右

步骤8

进行打包

阅读更多

程序员接私活必备10 个开源项目!

Tomcat 竟然有 bug,这我能信?

谷歌强推 AndroidX ,你还在应Support?

世界10大编程语言,Java不是第一,PHP才第五

史上最全 Java 中各种锁的介绍

相信自己,没有做不到的,只有想不到的

在这里获得的不仅仅是技术!

喜欢就给个“在看

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Readme - SwingLabs SwingX Project - http://swingx.dev.java.net<br><br><br>SwingX is a library of components and utilities extending the Java Swing library; read more at our website, <br>http://swingx.dev.java.net, and Wiki page, http://wiki.java.net/bin/view/Javadesktop/SwingLabsSwingX<br><br><br>Getting the Latest Source<br>=========================<br><br>1) Check out the lastest code<br>Download the latest release from our CVS repository; full instructions are at<br>https://swingx.dev.java.net/servlets/ProjectSource<br><br>but you can check out using the generic account "guest", with these settings<br><br>cvs -d :pserver:[email protected]:/cvs login<br><br>followed by<br><br>cvs -d :pserver:[email protected]:/cvs checkout swingx <br><br><br>Building the Source<br>===================<br>SwingX relies on Ant and Ant build files for controlling compilation, building docs, testing, etc. You can use our Ant build scripts or use your own--some IDEs make this easy to do.<br><br>To compile from the command line, you'll need to have Apache Ant installed; see http://ant.apache.org. <br><br>IMPORTANT: our default task in Ant also runs our unit tests, which are written using jUnit. You need to have Ant be aware of jUnit *before* compiling SwingX. We can't help you with <br>this--it's an Ant configuration issue. <br><br>If jUnit is not properly configured, you may get an error like this:<br> BUILD FAILED<br> c:\swingx\nbproject\build-impl.xml:407: Following error occured while executing this line<br> c:\\swingx\nbproject\build-impl.xml:127: Could not create task or type of type: junit.<br><br> Ant could not find the task or a class this task relies upon.<br><br>Suggestions: <br>- for Ant 1.5.x and previous, make sure optional.jar is in your ANT_HOME\lib directory.<br>- for Ant 1.6.x and above, make sure ant-junit.jar is in your ANT_HOME\lib directory, and that jUnit.jar is either in that directory as well OR listed on your CLASSPATH.<br><br>You can build SwingX by going to the command line and typing<br>ant<br><br>That should be it--this will test and build swingx.jar in the dist directory. <br><br><br>

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值