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

您所在的位置:网站首页 javafx登录界面布局 (四)创建基于maven的javaFX+springboot项目,用户界面与后台逻辑分离方式

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

#(四)创建基于maven的javaFX+springboot项目,用户界面与后台逻辑分离方式| 来源: 网络整理| 查看: 265

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

maven依赖

org.springframework.boot spring-boot-starter-actuator ${spring.boot.version} org.springframework.boot spring-boot-starter ${spring.boot.version} de.roskenet springboot-javafx-support ${springboot-javafx-support.version} 创建login.fxml文件,将文件放入resources下,因为springboot默认加载的资源为resources 创建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 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用来设置扫描包的中的类。

最后项目结构入下:

 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3