后臺管理系統(tǒng)框架搭建

1.新建maven項目bookmanage


image.png

image.png

image.png

image.png

2.新建項目成功后在pom.xml中修改JDK版本,并添加項目所需依賴

 <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>

  <dependencies>
    <!--Java工具集合的依賴-->
    <dependency>
      <groupId>cn.hutool</groupId>
      <artifactId>hutool-all</artifactId>
      <version>4.2.1</version>
    </dependency>
    <!--jdbc的mysql驅(qū)動依賴-->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.38</version>
    </dependency>
    <!--單元測試依賴-->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

Maven Projects視圖:


Maven Projects視圖

3.src源碼根據(jù)MVC模式劃分子包

  • entity包:存放實體類
  • dao包:存放各個實體的DAO接口
  • controller包:存放各個布局文件對應(yīng)的控制器類
  • utils包:存放工具類

3.main下新建resources,將其設(shè)為資源目錄,其下劃分各個子目錄

  • config:用來存放一些配置文件,如db.setting
  • css:用來存放樣式表文件
  • fxml:用來存放布局文件
  • img:用來存放圖片

為了做出一個主界面主體框架效果,先建立必須的幾個文件,如圖:


項目目錄結(jié)構(gòu)圖

4.啟動主類代碼MainApp.java,注意各個文件名和代碼對應(yīng)

public class MainApp extends Application {
  @Override
  public void start(Stage primaryStage) throws Exception {
      primaryStage.setTitle("Book Manage System");
      FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/main.fxml"));
      Parent root = fxmlLoader.load();
      Scene scene = new Scene(root);
      //界面最大化
      primaryStage.setMaximized(true);
      //logo設(shè)置 
      primaryStage.getIcons().add(new Image("/img/logo.png"));
      primaryStage.setScene(scene);
      primaryStage.show();
  }

  public static void main(String[] args) {
      launch(args);
  }
}

5.主控制器MainController.java

import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.StackPane;

import java.net.URL;
import java.util.ResourceBundle;

public class MainController implements Initializable {
    @FXML
    private StackPane mainContainer;

    @Override
    public void initialize(URL location, ResourceBundle resources) {

    }

   //顯示默認主頁數(shù)據(jù)
    public void listDefault() throws Exception {
        switchView("default.fxml");
    }

    //顯示圖書類別數(shù)據(jù)
    public void listType() throws Exception {
        switchView("type.fxml");
    }

    //顯示圖書數(shù)據(jù)
    public void listBook() throws Exception {
        switchView("book.fxml");
    }

    //封裝一個切換視圖的方法:用來根據(jù)fxml文件切換視圖內(nèi)容
    private void switchView(String fileName) throws Exception {
        //清除主面板之前內(nèi)容
        ObservableList<Node> list = mainContainer.getChildren();
        mainContainer.getChildren().removeAll(list);
        //讀取新的布局文件加入主面板
        AnchorPane anchorPane = new FXMLLoader(getClass().getResource("/fxml/" + fileName)).load();
        mainContainer.getChildren().add(anchorPane);
    }
}

6.主布局文件main.fxml

<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.effect.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.image.Image?>
<BorderPane
        xmlns:fx="http://javafx.com/fxml"
        fx:controller="com.soft1841.book.controller.MainController">
    <top>
        <AnchorPane prefHeight="80.0">
            <!--點擊這個文字顯示默認主頁數(shù)據(jù)-->
            <Label text="圖書后臺管理系統(tǒng)" onMouseClicked="#listDefault"
                   AnchorPane.topAnchor="20" AnchorPane.leftAnchor="10">
                <!--字體特效-->
                <effect>
                    <Reflection bottomOpacity="0.2" fraction="0.5" topOffset="-5.0"/>
                </effect>
                <font>
                    <Font name="System Bold" size="26.0"/>
                </font>
            </Label>
            <ImageView fitWidth="45" fitHeight="45" AnchorPane.topAnchor="15" AnchorPane.rightAnchor="120">
                <Image url="/img/me.png"/>
            </ImageView>
            <Button text="退出系統(tǒng)" AnchorPane.topAnchor="20" AnchorPane.rightAnchor="20"/>
        </AnchorPane>
    </top>
    <center>
        <!--分割面板-->
        <SplitPane>
            <!--左側(cè)的導(dǎo)航菜單部分-->
            <AnchorPane minWidth="200">
                <!--采用風(fēng)琴面板實現(xiàn)-->
                <Accordion AnchorPane.leftAnchor="0.0"
                           AnchorPane.rightAnchor="0.0"
                           AnchorPane.topAnchor="0.0">
                    <panes>
                       <!--由標(biāo)題面板組成,里面嵌入VBox,實現(xiàn)一級目錄和二級目錄效果-->
                        <TitledPane alignment="TOP_LEFT" text="類別管理">
                            <VBox minHeight="100" spacing="10">
                                <!--點擊該按鈕,右側(cè)切換圖書類別數(shù)據(jù)-->
                                <Button text="圖書類別" onAction="#listType"/>
                                <Button text="分類統(tǒng)計"/>
                            </VBox>
                        </TitledPane>
                        <TitledPane alignment="TOP_LEFT" text="圖書管理">
                            <VBox minHeight="100" spacing="10">
                                <!--點擊該按鈕,右側(cè)切換圖書數(shù)據(jù)-->
                                <Button text="圖書信息" onAction="#listBook"/>
                                <Button text="統(tǒng)計分析"/>
                            </VBox>
                        </TitledPane>
                        <TitledPane alignment="TOP_LEFT" text="用戶管理">
                            <VBox minHeight="130" spacing="10">
                                <Button text="管理員信息"/>
                                <Button text="讀者信息"/>
                                <Button text="統(tǒng)計分析"/>
                            </VBox>
                        </TitledPane>
                        <TitledPane alignment="TOP_LEFT" text="借閱管理">
                            <VBox minHeight="130" spacing="10">
                                <Button text="借閱查詢"/>
                                <Button text="統(tǒng)計分析"/>
                            </VBox>
                        </TitledPane>
                        <TitledPane alignment="TOP_LEFT" text="系統(tǒng)維護">
                            <VBox minHeight="130" spacing="10">
                                <Button text="系統(tǒng)初始化"/>
                                <Button text="數(shù)據(jù)備份"/>
                                <Button text="主題設(shè)置"/>
                            </VBox>
                        </TitledPane>
                    </panes>
                </Accordion>
            </AnchorPane>

           <!--右側(cè)的主體內(nèi)容部分,采用StackPane實現(xiàn)一種卡片切換效果-->
            <StackPane fx:id="mainContainer" minWidth="1060">
                <!--加載外部的fxml文件,顯示默認的主體內(nèi)容-->
                <fx:include source="default.fxml"/>
                <padding>
                    <Insets top="10" left="30" bottom="5" right="10"/>
                </padding>
            </StackPane>
            <padding>
                <Insets top="10"/>
            </padding>
        </SplitPane>
    </center>
</BorderPane>

7.default.fxml,默認的主界面主體內(nèi)容,暫時先放一個圖片占位

<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.image.Image?>
<AnchorPane xmlns="http://javafx.com/javafx"
           xmlns:fx="http://javafx.com/fxml"
           fx:controller="com.soft1841.book.controller.MainController">
   <ImageView AnchorPane.topAnchor="20" AnchorPane.leftAnchor="20">
       <Image url="/img/book.jpg"/>
   </ImageView>
</AnchorPane>

8.type.fxml,圖書類別數(shù)據(jù)展示,暫時先放一個文本標(biāo)簽占位

<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.control.Label?>
<AnchorPane xmlns="http://javafx.com/javafx"
            xmlns:fx="http://javafx.com/fxml"
            fx:controller="com.soft1841.book.controller.MainController">
    <Label text="圖書類別數(shù)據(jù)顯示"/>
</AnchorPane>

9.book.fxml,圖書信息數(shù)據(jù)展示,暫時先放一個ListView占位

<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.image.Image?>
<AnchorPane xmlns="http://javafx.com/javafx"
            xmlns:fx="http://javafx.com/fxml"
            fx:controller="com.soft1841.book.controller.MainController">
    <ListView prefWidth="600" prefHeight="300">
        <HBox spacing="30">
            <Label text="測試書籍"/>
            <Label text="匿名"/>
            <Label text="價格:88.8"/>
            <ImageView fitWidth="100" fitHeight="100">
                <Image url="/img/book.jpg"/>
            </ImageView>
        </HBox>
        <HBox spacing="30">
            <Label text="測試書籍"/>
            <Label text="匿名"/>
            <Label text="價格:88.8"/>
            <ImageView fitWidth="100" fitHeight="100">
                <Image url="/img/book.jpg"/>
            </ImageView>
        </HBox>
        <HBox spacing="30">
            <Label text="測試書籍"/>
            <Label text="匿名"/>
            <Label text="價格:88.8"/>
            <ImageView fitWidth="100" fitHeight="100">
                <Image url="/img/book.jpg"/>
            </ImageView>
        </HBox>
    </ListView>
</AnchorPane>

運行說明

  • 啟動主界面,整體是BorderPane布局
  • 頂部顯示一些基本信息,點擊左側(cè)“圖書后臺管理系統(tǒng)”文字可以實現(xiàn)“主頁”的效果
  • 中間部分由SplitPane分割成左右兩塊
  • 左側(cè)為一個風(fēng)琴面板+標(biāo)題面板,實現(xiàn)左側(cè)導(dǎo)航效果
  • 右側(cè)一個StackPane,由左側(cè)點擊不同的功能選項切換不同的布局文件,實現(xiàn)卡片效果,暫時只做了“圖書類別”、“圖書信息”兩個
運行效果圖:
  • 啟動界面


    啟動界面
  • 點擊左側(cè)“類別管理”下的“圖書類別”功能


    圖書類別
  • 點擊左側(cè)“圖書管理”下的“圖書信息”功能


    圖書信息
  • 點擊左上角“圖書后臺管理系統(tǒng)”文字,可切換到默認主頁


    image.png

附需要用到的圖:


book.jpg
logo.png
me.png

v1.0版功能演示:https://www.screencast.com/t/RpD8lvLP

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容