Selaa lähdekoodia

feat:使用BootstrapFX样式库

yangyi 1 kuukausi sitten
vanhempi
sitoutus
4f66fdafb3

+ 5 - 0
client/pom.xml

@@ -32,6 +32,11 @@
             <groupId>org.projectlombok</groupId>
             <artifactId>lombok</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.kordamp.bootstrapfx</groupId>
+            <artifactId>bootstrapfx-core</artifactId>
+            <version>0.4.0</version>
+        </dependency>
         <dependency>
             <groupId>space.anyi</groupId>
             <artifactId>common</artifactId>

+ 7 - 0
client/src/main/java/space/anyi/client/App.java

@@ -18,21 +18,28 @@ public class App extends Application {
         stage.show();
     }
 
+    private static void addBootstrapFX(Scene scene) {
+        scene.getStylesheets().add("org/kordamp/bootstrapfx/bootstrapfx.css");
+    }
+
     public static void showLoginScene() throws Exception {
         FXMLLoader loader = new FXMLLoader(App.class.getResource("/fxml/login.fxml"));
         Scene scene = new Scene(loader.load());
+        addBootstrapFX(scene);
         primaryStage.setScene(scene);
     }
 
     public static void showRegisterScene() throws Exception {
         FXMLLoader loader = new FXMLLoader(App.class.getResource("/fxml/register.fxml"));
         Scene scene = new Scene(loader.load());
+        addBootstrapFX(scene);
         primaryStage.setScene(scene);
     }
 
     public static void showMainScene() throws Exception {
         FXMLLoader loader = new FXMLLoader(App.class.getResource("/fxml/main.fxml"));
         Scene scene = new Scene(loader.load());
+        addBootstrapFX(scene);
         primaryStage.setScene(scene);
     }
 

+ 1 - 1
client/src/main/resources/fxml/login.fxml

@@ -9,6 +9,6 @@
     <Label text="校园书市" style="-fx-font-size: 22px; -fx-font-weight: bold;"/>
     <TextField fx:id="usernameField" promptText="用户名" maxWidth="300"/>
     <PasswordField fx:id="passwordField" promptText="密码" maxWidth="300"/>
-    <Button text="登录" onAction="#handleLogin" maxWidth="300" prefWidth="300"/>
+    <Button text="登录" onAction="#handleLogin" maxWidth="300" prefWidth="300" styleClass="btn,btn-primary"/>
     <Hyperlink text="没有账号?立即注册" onAction="#handleRegister"/>
 </VBox>

+ 13 - 13
client/src/main/resources/fxml/main.fxml

@@ -8,7 +8,7 @@
     <top>
         <HBox alignment="CENTER_LEFT" spacing="10" style="-fx-background-color: #2c3e50; -fx-padding: 10 15;">
             <Label fx:id="welcomeLabel" text="欢迎" style="-fx-text-fill: white; -fx-font-size: 16px;" HBox.hgrow="ALWAYS"/>
-            <Button text="退出登录" onAction="#handleLogout" style="-fx-background-color: #e74c3c; -fx-text-fill: white;"/>
+            <Button text="退出登录" onAction="#handleLogout" styleClass="btn,btn-danger"/>
         </HBox>
     </top>
     <center>
@@ -19,7 +19,7 @@
                     <HBox spacing="10">
                         <TextField fx:id="searchField" promptText="搜索书名/作者..." HBox.hgrow="ALWAYS"/>
                         <ComboBox fx:id="categoryCombo" prefWidth="150"/>
-                        <Button text="搜索" onAction="#handleSearch"/>
+                        <Button text="搜索" onAction="#handleSearch" styleClass="btn,btn-info"/>
                     </HBox>
                     <SplitPane dividerPositions="0.6" VBox.vgrow="ALWAYS">
                         <TableView fx:id="bookTable">
@@ -42,7 +42,7 @@
                             <Label fx:id="detailPrice" text="-"/>
                             <Label fx:id="detailStock" text="-"/>
                             <TextField fx:id="quantityField" promptText="数量" maxWidth="100"/>
-                            <Button text="购买" onAction="#handlePurchase" style="-fx-background-color: #27ae60; -fx-text-fill: white;"/>
+                            <Button text="购买" onAction="#handlePurchase" styleClass="btn,btn-success"/>
                         </VBox>
                     </SplitPane>
                 </VBox>
@@ -50,7 +50,7 @@
             <Tab text="我的交易" closable="false">
                 <VBox spacing="10">
                     <padding><Insets top="10" right="10" bottom="10" left="10"/></padding>
-                    <Button text="刷新" onAction="#handleLoadTransactions"/>
+                    <Button text="刷新" onAction="#handleLoadTransactions" styleClass="btn,btn-secondary"/>
                     <TableView fx:id="transTable" VBox.vgrow="ALWAYS">
                         <columns>
                             <TableColumn fx:id="transIdCol" text="交易编号" prefWidth="80"/>
@@ -73,14 +73,14 @@
                     <HBox spacing="10"><Label text="电话:" prefWidth="100"/><TextField fx:id="profilePhone"/></HBox>
                     <HBox spacing="10"><Label text="院系:" prefWidth="100"/><TextField fx:id="profileDept"/></HBox>
                     <HBox spacing="10"><Label text="信用分:" prefWidth="100"/><Label fx:id="profileCredit"/></HBox>
-                    <Button text="保存修改" onAction="#handleUpdateProfile"/>
+                    <Button text="保存修改" onAction="#handleUpdateProfile" styleClass="btn,btn-primary"/>
                 </VBox>
             </Tab>
             <Tab fx:id="sellerTab" text="卖家中心" closable="false">
                 <VBox spacing="10">
                     <padding><Insets top="10" right="10" bottom="10" left="10"/></padding>
                     <Label text="我的书籍" style="-fx-font-weight: bold;"/>
-                    <Button text="刷新" onAction="#handleLoadMyBooks"/>
+                    <Button text="刷新" onAction="#handleLoadMyBooks" styleClass="btn,btn-secondary"/>
                     <TableView fx:id="myBookTable" VBox.vgrow="ALWAYS">
                         <columns>
                             <TableColumn fx:id="myBookIdCol" text="编号" prefWidth="50"/>
@@ -89,7 +89,7 @@
                             <TableColumn fx:id="myBookStockCol" text="库存" prefWidth="60"/>
                         </columns>
                     </TableView>
-                    <Button text="删除选中" onAction="#handleDeleteBook"/>
+                    <Button text="删除选中" onAction="#handleDeleteBook" styleClass="btn,btn-danger"/>
                     <TitledPane text="添加新书" expanded="false">
                         <GridPane hgap="10" vgap="8">
                             <padding><Insets top="10" right="10" bottom="10" left="10"/></padding>
@@ -99,7 +99,7 @@
                             <Label text="原价" GridPane.rowIndex="3" GridPane.columnIndex="0"/><TextField fx:id="newOriginalPrice" GridPane.rowIndex="3" GridPane.columnIndex="1"/>
                             <Label text="售价" GridPane.rowIndex="4" GridPane.columnIndex="0"/><TextField fx:id="newSellingPrice" GridPane.rowIndex="4" GridPane.columnIndex="1"/>
                             <Label text="库存" GridPane.rowIndex="5" GridPane.columnIndex="0"/><TextField fx:id="newStock" GridPane.rowIndex="5" GridPane.columnIndex="1"/>
-                            <Button text="添加书籍" onAction="#handleAddBook" GridPane.rowIndex="6" GridPane.columnIndex="1"/>
+                            <Button text="添加书籍" onAction="#handleAddBook" GridPane.rowIndex="6" GridPane.columnIndex="1" styleClass="btn,btn-success"/>
                         </GridPane>
                     </TitledPane>
                 </VBox>
@@ -108,7 +108,7 @@
                 <ScrollPane fitToWidth="true">
                     <VBox spacing="15">
                         <padding><Insets top="15" right="15" bottom="15" left="15"/></padding>
-                        <Button text="刷新数据" onAction="#handleLoadStatistics" maxWidth="200"/>
+                        <Button text="刷新数据" onAction="#handleLoadStatistics" maxWidth="200" styleClass="btn,btn-secondary"/>
                         <TitledPane text="总览" expanded="true">
                             <HBox spacing="40">
                                 <padding><Insets top="10" right="10" bottom="10" left="10"/></padding>
@@ -156,7 +156,7 @@
                     <padding><Insets top="10" right="10" bottom="10" left="10"/></padding>
                     <Label text="用户管理"
                            style="-fx-font-weight: bold; -fx-font-size: 16px;"/>
-                    <Button text="刷新用户" onAction="#handleLoadAllUsers"/>
+                    <Button text="刷新用户" onAction="#handleLoadAllUsers" styleClass="btn,btn-secondary"/>
                     <TableView fx:id="userTable" VBox.vgrow="ALWAYS">
                         <columns>
                             <TableColumn fx:id="userIdCol" text="编号" prefWidth="50"/>
@@ -168,9 +168,9 @@
                             <TableColumn fx:id="userSellerCol" text="卖家" prefWidth="60"/>
                         </columns>
                     </TableView>
-                    <Button text="删除选中用户" onAction="#handleDeleteUser" style="-fx-background-color: #e74c3c; -fx-text-fill: white;"/>
+                    <Button text="删除选中用户" onAction="#handleDeleteUser" styleClass="btn,btn-danger"/>
                     <Label text="全部交易" style="-fx-font-weight: bold; -fx-font-size: 16px;"/>
-                    <Button text="刷新交易" onAction="#handleLoadAllTransactions"/>
+                    <Button text="刷新交易" onAction="#handleLoadAllTransactions" styleClass="btn,btn-secondary"/>
                     <TableView fx:id="allTransTable" VBox.vgrow="ALWAYS">
                         <columns>
                             <TableColumn fx:id="allTransIdCol" text="交易编号" prefWidth="60"/>
@@ -181,7 +181,7 @@
                             <TableColumn fx:id="allTransTimeCol" text="时间" prefWidth="200"/>
                         </columns>
                     </TableView>
-                    <Button text="删除选中交易" onAction="#handleDeleteTransaction" style="-fx-background-color: #e74c3c; -fx-text-fill: white;"/>
+                    <Button text="删除选中交易" onAction="#handleDeleteTransaction" styleClass="btn,btn-danger"/>
                 </VBox>
             </Tab>
         </TabPane>

+ 1 - 1
client/src/main/resources/fxml/register.fxml

@@ -13,6 +13,6 @@
     <TextField fx:id="emailField" promptText="邮箱" maxWidth="300"/>
     <TextField fx:id="phoneField" promptText="电话" maxWidth="300"/>
     <TextField fx:id="deptField" promptText="院系" maxWidth="300"/>
-    <Button text="注册" onAction="#handleRegister" maxWidth="300" prefWidth="300"/>
+    <Button text="注册" onAction="#handleRegister" maxWidth="300" prefWidth="300" styleClass="btn,btn-primary"/>
     <Hyperlink text="已有账号?去登录" onAction="#handleBack"/>
 </VBox>