下面来介绍创建maven的javaFX+springboot项目,基于用户界面与后天逻辑分离的方式,用户界面使用fxml文件来常见,类似于jsp,可以引入css文件修饰界面

maven依赖

        <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>de.roskenet</groupId>
<artifactId>springboot-javafx-support</artifactId>
<version>${springboot-javafx-support.version}</version>
</dependency>
  • 创建login.fxml文件,将文件放入resources下,因为springboot默认加载的资源为resources
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?> <AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity"
prefHeight="588.0" prefWidth="802.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2"
fx:controller="com.dome.controller.LoginController">
<children>
<HBox layoutX="122.0" layoutY="108.0" prefHeight="372.0" prefWidth="526.0">
<children>
<Label alignment="CENTER" contentDisplay="CENTER" prefHeight="30.0" prefWidth="70.0" text="用户名" textAlignment="LEFT">
<font>
<Font size="18.0" fx:id="x1" />
</font>
<HBox.margin>
<Insets bottom="10.0" left="50.0" right="10.0" top="100.0" />
</HBox.margin>
</Label>
<TextField fx:id="userName" id="username" prefHeight="30.0" prefWidth="200.0">
<HBox.margin>
<Insets bottom="10.0" right="10.0" top="100.0" />
</HBox.margin>
</TextField>
<Label alignment="CENTER" contentDisplay="CENTER" font="$x1" prefHeight="30.0" prefWidth="70.0" text="密 码" textAlignment="LEFT">
<HBox.margin>
<Insets bottom="10.0" left="-290.0" top="140.0" />
</HBox.margin>
</Label>
<TextField fx:id="passWord" id="password" prefHeight="30.0" prefWidth="200.0">
<HBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="140.0" />
</HBox.margin>
</TextField>
<Button id="region" contentDisplay="CENTER" font="$x1" minHeight="28.0" mnemonicParsing="false" opacity="0.79" prefHeight="35.0" prefWidth="75.0" text="注册" textAlignment="CENTER">
<HBox.margin>
<Insets bottom="10.0" left="-240.0" top="200.0" />
</HBox.margin>
</Button>
<Button id="login" font="$x1" minHeight="28.0" mnemonicParsing="false" opacity="0.79" prefHeight="35.0" prefWidth="75.0"
text="登录" onAction="#btnClick" >
<HBox.margin>
<Insets bottom="10.0" left="60.0" top="200.0" />
</HBox.margin>
</Button>
</children>
</HBox>
</children>
</AnchorPane>
  • 创建LoginFXML类,指定fxml文件的路径,及引入fxml文件所需的样式
import de.felixroske.jfxsupport.AbstractFxmlView;
import de.felixroske.jfxsupport.FXMLView; @FXMLView(value = "/static/fxml/login.fxml", css = {"/static/style/login.css"},title = "用户登录")
public class LoginFXML extends AbstractFxmlView { }

可以来了解下FXMLView的参数

@Component
@Retention(RetentionPolicy.RUNTIME)
public @interface FXMLView {
String value() default ""; String[] css() default {}; String bundle() default ""; String title() default ""; String stageStyle() default "UTILITY";
}
  • 创建LoginController,与用户界面进行交互
import com.dome.MainController;
import com.dome.domain.Student;
import com.dome.service.IStudentService;
import com.dome.view.LoginFXML;
import de.felixroske.jfxsupport.FXMLController;
import javafx.event.ActionEvent;
import javafx.fxml.Initializable;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import org.springframework.beans.factory.annotation.Autowired; import java.net.URL;
import java.util.List;
import java.util.ResourceBundle; @FXMLController
public class LoginController implements Initializable { @FXML
private Button button;
@FXML
private TextField userName; @Autowired
private IStudentService studentService; private ResourceBundle resourceBundle; @Override
public void initialize(URL location, ResourceBundle resources) {
resourceBundle = resources;
} @FXML
public void btnClick(ActionEvent actionEvent) {
List<Student> students = studentService.listAll();
userName.setText("helloWorld");
} @FXML
public void btnLoginClick(ActionEvent actionEvent) {
MainController.showView(LoginFXML.class);
} }
  • 创建main方法,启动项目
import com.dome.view.ExportClassEntityFXML;
import com.dome.view.LoginFXML;
import de.felixroske.jfxsupport.AbstractJavaFxApplicationSupport;
import javafx.stage.Stage;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan; /**
* maven构建JavaFX+SpringBoot项目启动类
*/
@ComponentScan({"com.dome.view","com.dome.controller","com.dome.service"})
@SpringBootApplication
public class MainController extends AbstractJavaFxApplicationSupport { public static void main(String[] args) {
launch(MainController.class, ExportClassEntityFXML.class, args);
} @Override
public void start(Stage stage) throws Exception {
super.start(stage);
stage.setTitle("用户登录");
//窗口最大化显示
// Rectangle2D primaryScreenBounds = Screen.getPrimary().getVisualBounds();
// stage.setX(primaryScreenBounds.getMinX());
// stage.setY(primaryScreenBounds.getMinY());
// stage.setWidth(primaryScreenBounds.getWidth());
// stage.setHeight(primaryScreenBounds.getHeight());
// stage.setMaximized(true);//设置窗口最大化
// stage.setFullScreen(true);//全屏显示,Esc退出
// stage.setAlwaysOnTop(true);//始终显示在其他窗口之上
}
}

其中ComponentScan用来设置扫描包的中的类。

最后项目结构入下:

(四)创建基于maven的javaFX+springboot项目,用户界面与后台逻辑分离方式的更多相关文章

  1. (三)创建基于maven的javaFX+springboot项目创建

    创建基于maven的javaFx+springboot项目有两种方式,第一种为通过非编码的方式来设计UI集成springboot:第二种为分离用户界面(UI)和后端逻辑集成springboot,其中用 ...

  2. (二)创建基于maven的javaFX项目

    首先使用IDEA创建一个javaFX项目 点击finish,这就创建完成了JavaFX项目,只有将其转换为maven项目即可,如图:

  3. 使用IDEA创建基于Maven SpringMvc项目

    使用IDEA创建基于Maven SpringMvc项目 1.通过程序启动——create project,或者file--New-projec打开New project 2.自定义groupid等信息 ...

  4. 转:基于Maven管理的JavaWeb项目目录结构参考

    通常在创建JavaWeb项目时多多少少都会遵循一些既定的比较通用的目录结构,下面分享一张基于Maven管理的JavaWeb项目目录结构参考图: 上图仅是参考,不同项目不同团队都有自己的约定和规范. 个 ...

  5. IntelliJ IDEA基于maven构建的web项目找不到jar包

    基于maven构建的springMVC项目,下载好jar包import后,运行提示ClassNotFoundException: java.lang.ClassNotFoundException: o ...

  6. 创建基于maven的项目模版

    我们在实际工作中 ,有些项目的架构是相似的,例如基于 restful的接口项目,如果每次都重新搭建一套架构或者通过拷贝建立一个项目难免有些得不偿失,这里我们可以用maven的archtype建立项目模 ...

  7. 从头开始基于Maven搭建SpringMVC+Mybatis项目(3)

    接上文内容,本节介绍基于Mybatis的查询和分页功能,并展示一个自定义的分页标签,可重复使用以简化JSP页面的开发. 从头阅读传送门 在上一节中,我们已经使用Maven搭建好了项目的基础结构,包括一 ...

  8. Springboot 创建的maven获取resource资源下的文件的两种方式

    Springboot 创建的maven项目 打包后获取resource下的资源文件的两种方式: 资源目录: resources/config/wordFileXml/wordFileRecord.xm ...

  9. 学习笔记——Maven实战(四)基于Maven的持续集成实践

    Martin的<持续集成> 相信很多读者和我一样,最早接触到持续集成的概念是来自Martin的著名文章<持续集成>,该文最早发布于2000年9月,之后在2006年进行了一次修订 ...

随机推荐

  1. Flask+uwsgi+Nginx+Ubuntu部署教程

    学习 Flask,写完一个 Flask 应用需要部署的时候,就想着折腾自己的服务器.根据搜索的教程照做,对于原理一知半解,磕磕碰碰,只要运行起来了,谢天谢地然后不再折腾了,到下一次还需要部署时,这样的 ...

  2. Flask Response响应(flask中设置响应信息的方法,返回json数据的方法)

    设置响应信息的方法 1.  返回自定义的响应头,有两种方式: (1)  第一种是:视图函数return的时候,使用元组,返回自定义的信息 返回的时候的状态码可以自定义信息:"状态码   自定 ...

  3. 前端单元测试,以及给现有的vue项目添加jest + Vue Test Utils的配置

    文章原址:https://www.cnblogs.com/yalong/p/11714393.html 背景介绍: 以前写的公共组件,后来需要添加一些功能,添加了好几次,每次修改我都要测试好几遍保证以 ...

  4. kettle转换和任务的基本使用

    0 创建转换 并保存0816_em.ktr 1 主对象树中选择DB连接,创建2个DB连接 2 创建表输入 核心对象树中选择输入>表输入 3 核心对象树中选择输出>插入/更新表 并连线 4 ...

  5. Python3.x运行Python2.x代码报错 syntax error "Missing parentheses in call to 'print'

    #另外一种错误 SyntaxError: Missing parentheses in call to 'print'. Did you mean print( 查看代码,格式如下: print &q ...

  6. R语言 我要如何开始R语言_数据分析师

    R语言 我要如何开始R语言_数据分析师 我要如何开始R语言? 很多时候,我们的老板跟我们说,这个东西你用R语言去算吧,Oh,My god!什么是R语言?我要怎么开始呢? 其实回答这个问题很简单,首先, ...

  7. GlusterFS集群

    使用架构: 2台机器安装 GlusterFS 组成一个 Distributed Replicated Volumes集群 192.168.0.92 服务端 192.168.0.93 服务端 192.1 ...

  8. Daily in Ipin

    Friday, October 23 1. [道高一尺,墙高一丈:互联网封锁是如何升级的] Monday, October 12 1. 晕死,忘了ubuntu的登录密码,鼓捣了半个小时,终于成功进入系 ...

  9. hive中case命令

  10. Django-DRF(路由与扩展功能)

    一. 视图集与路由的使用 使用视图集ViewSet,可以将一系列逻辑相关的动作放到一个类中: list() 提供一组数据 retrieve() 提供单个数据 create() 创建数据 update( ...