使用JDBC+javafx写一个简单功能齐全的图书管理系统2

简介: 使用JDBC+javafx写一个简单功能齐全的图书管理系统

2)resources(为资源文件包,可以看链接文章了解)

Ⅰ、book包

add.fxml

<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.text.Text?>
<?import java.net.URL?>
<GridPane xmlns="http://javafx.com/javafx"
          xmlns:fx="http://javafx.com/fxml"
          fx:controller="com.hk.sky.bookmanager.controller.AddController"
          prefHeight="400.0" prefWidth="600.0" hgap="20" vgap="20">
    <padding>
        <Insets left="20" top="30"/>
    </padding>
    <Text text="类型:" GridPane.rowIndex="0" GridPane.columnIndex="0"/>
    <ComboBox  GridPane.halignment="CENTER" GridPane.rowIndex="0" GridPane.columnIndex="1" fx:id="categoryComboBox">
    </ComboBox>
    <Text text="书名:" GridPane.rowIndex="1" GridPane.columnIndex="0"/>
    <TextField fx:id="bookName" GridPane.rowIndex="1" GridPane.columnIndex="1"/>
    <Text text="作者:" GridPane.rowIndex="2" GridPane.columnIndex="0"/>
    <TextField fx:id="bookAuthor" GridPane.rowIndex="2" GridPane.columnIndex="1"/>
    <Text text="出版社:" GridPane.rowIndex="3" GridPane.columnIndex="0"/>
    <TextField fx:id="bookPublisher" GridPane.rowIndex="3" GridPane.columnIndex="1"/>
    <Text text="价格:" GridPane.rowIndex="4" GridPane.columnIndex="0"/>
    <TextField fx:id="bookPrice" GridPane.rowIndex="4" GridPane.columnIndex="1"/>
    <Text text="内容简介:" GridPane.rowIndex="5" GridPane.columnIndex="0"/>
    <TextField fx:id="detail" GridPane.rowIndex="5" GridPane.columnIndex="1"/>
    <Text text="库存:" GridPane.rowIndex="6" GridPane.columnIndex="0"/>
    <TextField fx:id="bookStock" GridPane.rowIndex="6" GridPane.columnIndex="1"/>
    <Button fx:id="add" text="添加" onAction="#addBook" GridPane.rowIndex="7" GridPane.columnIndex="0" GridPane.columnSpan="2"
            GridPane.halignment="CENTER" styleClass="aBtn" visible="true" > </Button>
    <Button fx:id="edit" onAction="#editBook" GridPane.rowIndex="7" GridPane.columnIndex="0" GridPane.columnSpan="2"
            GridPane.halignment="CENTER" styleClass="eBtn" visible="false"> </Button>
    <stylesheets>
        <URL value="@add.css"/>
    </stylesheets>
</GridPane>

houtai.fxml

<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.Text?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.cell.PropertyValueFactory?>
<?import java.net.URL?>
<AnchorPane xmlns="http://javafx.com/javafx"
            xmlns:fx="http://javafx.com/fxml"
            fx:controller="com.hk.sky.bookmanager.controller.HouTaiController"
            prefHeight="550.0" prefWidth="580.0" styleClass="ht">
    <Button fx:id="fh" text="返回" visible="false" onAction="#back"/>
    <Text id="wm" fx:id="welcomeMsg" AnchorPane.leftAnchor="290" AnchorPane.topAnchor="10"/>
    <Button  text="修改密码"  onAction="#xgmm" AnchorPane.leftAnchor="585"/>
    <Button  text="注销"  onAction="#zx" AnchorPane.leftAnchor="658"/>
    <HBox AnchorPane.leftAnchor="180" AnchorPane.topAnchor="35">
        <ComboBox    fx:id="categorySelect">
        </ComboBox>
        <TextField fx:id="search">
            <HBox.margin>
                <Insets left="10" />
            </HBox.margin>
        </TextField>
        <Button text="查询" onAction="#searchBtn">
            <HBox.margin>
                <Insets left="10" right="10"/>
            </HBox.margin>
        </Button>
        <Button text="删除" onAction="#deleteBtn">
            <HBox.margin>
                <Insets right="10"/>
            </HBox.margin>
        </Button>
        <Button text="添加" onAction="#addBtn">
        </Button>
    </HBox>
    <TableView styleClass="table-view"
               fx:id="bookTable" AnchorPane.leftAnchor="10" AnchorPane.topAnchor="70" prefHeight="287" prefWidth="680">
        <columns>
            <TableColumn text="编号" prefWidth="40">
                <cellValueFactory>
                    <PropertyValueFactory property="id"/>
                </cellValueFactory>
            </TableColumn>
            <TableColumn text="书名"  prefWidth="100">
                <cellValueFactory>
                    <PropertyValueFactory property="bookName"/>
                </cellValueFactory>
            </TableColumn>
            <TableColumn text="作者">
                <cellValueFactory>
                    <PropertyValueFactory property="author"/>
                </cellValueFactory>
            </TableColumn>
            <TableColumn text="价格">
                <cellValueFactory>
                    <PropertyValueFactory property="price"/>
                </cellValueFactory>
            </TableColumn>
            <TableColumn text="库存">
                <cellValueFactory>
                    <PropertyValueFactory property="stock"/>
                </cellValueFactory>
            </TableColumn>
            <TableColumn text="出版社" prefWidth="130">
                <cellValueFactory>
                    <PropertyValueFactory property="publisher"/>
                </cellValueFactory>
            </TableColumn>
        </columns>
    </TableView>
    <FlowPane AnchorPane.leftAnchor="150" AnchorPane.bottomAnchor="20" hgap="20" alignment="CENTER">
        <Text fx:id="searchCount"/>
        <Text fx:id="searchPage" text="第1页"/>
        <Button onAction="#start" text="首页"/>
        <Button onAction="#up" text="上一页"/>
        <Button onAction="#next" text="下一页"/>
        <Button onAction="#end" text="尾页"/>
    </FlowPane>
    <stylesheets>
        <URL value="@houtai.css"/>
    </stylesheets>
</AnchorPane>

show.fxml

<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.text.Text?>
<?import javafx.geometry.Insets?>
<?import java.net.URL?>
<GridPane xmlns="http://javafx.com/javafx"
          xmlns:fx="http://javafx.com/fxml"
          fx:controller="com.hk.sky.bookmanager.controller.ShowController"
          hgap="8" vgap="8">
    <padding>
        <Insets left="10" top="20" />
    </padding>
    <ImageView GridPane.rowIndex="0" GridPane.columnIndex="0" GridPane.rowSpan="5" fitWidth="75" fitHeight="90">
        <Image url="@image/book.png" />
    </ImageView>
    <Text GridPane.rowIndex="0" GridPane.columnIndex="1" text="编号:"/>
    <Text fx:id="bookId" GridPane.rowIndex="0" GridPane.columnIndex="2"/>
    <Text GridPane.rowIndex="1" GridPane.columnIndex="1" text="书名:"/>
    <Text fx:id="bookName" GridPane.rowIndex="1" GridPane.columnIndex="2"/>
    <Text GridPane.rowIndex="2" GridPane.columnIndex="1" text="作者:"/>
    <Text fx:id="bookAuthor" GridPane.rowIndex="2" GridPane.columnIndex="2"/>
    <Text GridPane.rowIndex="3" GridPane.columnIndex="1" text="价格:"/>
    <Text fx:id="bookPrice" GridPane.rowIndex="3" GridPane.columnIndex="2"/>
    <Text GridPane.rowIndex="4" GridPane.columnIndex="1" text="库存:"/>
    <Text fx:id="bookStock" GridPane.rowIndex="4" GridPane.columnIndex="2"/>
    <Text GridPane.rowIndex="5" GridPane.columnIndex="1" text="出版社:"/>
    <Text fx:id="bookPublish" GridPane.rowIndex="5" GridPane.columnIndex="2"/>
    <Text GridPane.rowIndex="6" GridPane.columnIndex="0" text="详情" GridPane.halignment="CENTER" GridPane.columnSpan="3"
          styleClass="xq"/>
    <Text fx:id="bookDetail" GridPane.rowIndex="7" GridPane.columnIndex="0" GridPane.columnSpan="3" wrappingWidth="260"/>
    <stylesheets>
        <URL value="@show.css"/>
    </stylesheets>
</GridPane>

add.css

.aBtn{
    -fx-background-color: #0274FE;
    -fx-pref-width: 80px;
    -fx-pref-height: 40px;
    -fx-background-radius: 10px;
    -fx-text-fill: #fff;
    /*鼠标在上面会变成手的形状*/
    -fx-cursor: hand;
    /*加粗*/
    -fx-font-weight:bold;
}
.eBtn{
    -fx-background-color: #0274FE;
    /*按钮长宽*/
    -fx-pref-width: 80px;
    -fx-pref-height: 40px;
    -fx-background-radius: 10px;
    /*设置文字颜色*/
    -fx-text-fill: #fff;
    -fx-cursor: hand;
}

houtai.css

#wm{
-fx-font-size: 14px;
-fx-font-family:"Microsoft YaHei UI";
}
.table-view .table-column{
  -fx-alignment:CENTER;
  -fx-font-weight:bold;
  /*点击文字会变色*/
  -fx-light-text-color:red;
}
.ht{
/*设置背景,其中链接为网络图像链接*/
-fx-background-image:url("https://b.zol-img.com.cn/desk/bizhi/image/10/960x600/1598319721647.jpg");
-fx-background-repeat:stretch;
-fx-background-size:700 430;
}
/*设置表格为透明,下面四个样式缺一不可*/
.table-view {
  -fx-background-color: transparent;
}
/*表格最上面一行导航栏设置透明*/
.table-column {
  -fx-background-color: transparent;
}
.table-view .column-header-background {
  -fx-background-color:transparent;
 }
/*表格内容透明*/
.table-row-cell {
    -fx-background-color:transparent;
}

show.css

.xq{
-fx-font-size: 14px;
/*设置字体颜色*/
-fx-fill: RED;
}

image大家可以在书籍模型图片中找,有很多种图片给大家选择

Ⅱ、 login包

login.css

#login-title {
    -fx-font-size: 26px;
    -fx-font-family: "Microsoft YaHei UI";
}
.login-btn {
    -fx-background-color: #0274FE;
    /*设置按钮长宽*/
    -fx-pref-width: 50px;
    -fx-pref-height: 30px;
    /*设置按钮角边距*/
    -fx-background-radius: 30px;
    -fx-text-fill: #fff;
    -fx-cursor: hand;
}
.enroll-btn {
    -fx-background-color: #0274FE;
    -fx-pref-width: 150px;
    -fx-pref-height: 30px;
    /*设置按钮角边距*/
    -fx-background-radius: 10px;
    -fx-text-fill: #fff;
    -fx-cursor: hand;
}
.login{
/*设置背景,其中链接为网络图像链接*/
-fx-background-image:url("https://ts1.cn.mm.bing.net/th/id/R-C.2007af8279430f7cdae54e3714cceeef?rik=E0YMmdkLdVaw8Q&riu=http%3a%2f%2f5b0988e595225.cdn.sohucs.com%2fimages%2f20181117%2f8e26ba707bf74f6bb8a87cf1a3f35ffb.gif&ehk=OBammaDlXjLLw29ouO%2b6nENFuzJNMOFwirTInUSCmfo%3d&risl=&pid=ImgRaw&r=0");
-fx-background-repeat:stretch;
-fx-background-size:290 240;
}
.enroll{
/*设置背景,其中链接为网络图像链接*/
-fx-background-image:url("https://ts1.cn.mm.bing.net/th/id/R-C.0bd134123caa7005ec50e75b45218a54?rik=lSaVSid3n%2bfrXg&riu=http%3a%2f%2fwww.kutoo8.com%2fupload%2fimage%2f81433892%2f12.jpg&ehk=cjol7ne5lTOk6iPRCR%2f2RIoGlffBEHdj9QO5RHUWYdk%3d&risl=&pid=ImgRaw&r=0");
-fx-background-repeat:stretch;
-fx-background-size:290 251;
}

enroll.fxml

<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.text.Text?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.PasswordField?>
<?import java.net.URL?>
<GridPane fx:controller="com.hk.sky.bookmanager.controller.EnrollController"
          xmlns:fx="http://javafx.com/fxml" vgap="10" hgap="10" styleClass="enroll">
    <padding>
        <Insets top="40" left="30"/>
    </padding>
    <Text id="login-title" fx:id="title" text="注 册" GridPane.rowIndex="0" GridPane.columnIndex="0" GridPane.columnSpan="2"
          GridPane.halignment="CENTER"/>
    <Label text="用户名:" GridPane.rowIndex="1" GridPane.columnIndex="0"/>
    <TextField fx:id="username1" GridPane.rowIndex="1" GridPane.columnIndex="1"/>
    <Label text="密码:" GridPane.rowIndex="2" GridPane.columnIndex="0"/>
    <PasswordField fx:id="password1" GridPane.rowIndex="2" GridPane.columnIndex="1"/>
    <Text fx:id="errorMsg" text="" GridPane.rowIndex="3" GridPane.columnIndex="0" GridPane.columnSpan="2"
          GridPane.halignment="CENTER"/>
    <Button text="申请注册" GridPane.rowIndex="4" GridPane.columnIndex="0" visible="true" fx:id="enroll"
            GridPane.columnSpan="2" GridPane.halignment="CENTER" onAction="#enrollBtn" styleClass="enroll-btn"/>
    <Button text="修改密码" GridPane.rowIndex="4" GridPane.columnIndex="0" visible="false" fx:id="alert"
            GridPane.columnSpan="2" GridPane.halignment="CENTER" onAction="#alertBtn" styleClass="enroll-btn"/>
    <stylesheets>
        <URL value="@login.css"/>
    </stylesheets>
</GridPane>

login.fxml

<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.text.Text?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.PasswordField?>
<?import java.net.URL?>
<?import javafx.scene.layout.HBox?>
<GridPane fx:controller="com.hk.sky.bookmanager.controller.LoginController"
          xmlns:fx="http://javafx.com/fxml" vgap="8" hgap="8" styleClass="login" >
    <padding>
        <Insets top="40" left="30"/>
    </padding>
    <Text id="login-title" text="登 录" GridPane.rowIndex="0" GridPane.columnIndex="0" GridPane.columnSpan="2"
          GridPane.halignment="CENTER"/>
    <Label text="用户名:" GridPane.rowIndex="1" GridPane.columnIndex="0"/>
    <TextField fx:id="username" GridPane.rowIndex="1" GridPane.columnIndex="1"/>
    <Label text="密码:" GridPane.rowIndex="2" GridPane.columnIndex="0"/>
    <PasswordField fx:id="password" GridPane.rowIndex="2" GridPane.columnIndex="1"/>
    <Text fx:id="errorMsg" GridPane.rowIndex="3" GridPane.columnIndex="1"/>
    <Button text="登录" GridPane.rowIndex="4" GridPane.columnIndex="0" GridPane.halignment="RIGHT"
            onAction="#checkLogin" styleClass="login-btn" >
    </Button>
    <Button text="注册" GridPane.rowIndex="4" GridPane.columnIndex="1" GridPane.halignment="RIGHT"
            onAction="#enrollLogin" styleClass="login-btn"/>
    <stylesheets>
        <URL value="@login.css"/>
    </stylesheets>
</GridPane>

5、效果展示(对应功能实现在相应代码中)

1)、登录功能


bb37b7ee87af4520bb84030fce6f933f.png



388c9e2d3e834af788a4771181d2ebae.png

2)、注册功能



fb3396f3b498484e9143db01551e49d5.png


1c9d1769a3ca438680efc20888ae89df.png



0644ceb838814f8399f47d9458deab46.png

3)、后台主页面(手机端图片违规了,请使用pc端进行查看)


4)、编辑页和添加页


ad68a5130e854ea0ba86b222cc398f3b.png

5)、修改密码页




5356de330f0e4ba0823708f4e298a802.png

6)、注销页



image.png

点击确定,则会弹出下面信息,则该账号无法再次使用,需要重新注册,或者使用其他账号。接下来则会显示出 空白账号密码 的登陆页面


46b03e185a264445a4c57a5420f6448f.png

目录
相关文章
|
7月前
|
SQL Java 数据库连接
JDBC编程相关知识(实现图书管理系统进阶版)(下)
JDBC编程相关知识(实现图书管理系统进阶版)
47 0
|
7月前
|
Java 关系型数据库 MySQL
JDBC编程相关知识(实现图书管理系统进阶版)(上)
JDBC编程相关知识(实现图书管理系统进阶版)
79 0
|
Java 数据库连接 数据库
大学的第一个项目,JDBC实现图书管理系统
大学的第一个项目,JDBC实现图书管理系统
136 1
|
Java 数据库连接 数据库
使用JDBC+javafx写一个简单功能齐全的图书管理系统1
使用JDBC+javafx写一个简单功能齐全的图书管理系统
210 0
|
XML JavaScript 前端开发
图书管理系统基于servlet+mysql+jdbc+html
代码3400多行,主要功能基本都实现了,但是极个别的内容由于时间比较匆忙,还要学习新的知识等,还需要改善。
162 0
|
2月前
|
Java 关系型数据库 MySQL
mysql5.7 jdbc驱动
遵循上述步骤,即可在Java项目中高效地集成MySQL 5.7 JDBC驱动,实现数据库的访问与管理。
512 1
|
2月前
|
SQL 分布式计算 关系型数据库
Hadoop-24 Sqoop迁移 MySQL到Hive 与 Hive到MySQL SQL生成数据 HDFS集群 Sqoop import jdbc ETL MapReduce
Hadoop-24 Sqoop迁移 MySQL到Hive 与 Hive到MySQL SQL生成数据 HDFS集群 Sqoop import jdbc ETL MapReduce
112 0
|
2月前
|
SQL 分布式计算 关系型数据库
Hadoop-23 Sqoop 数据MySQL到HDFS(部分) SQL生成数据 HDFS集群 Sqoop import jdbc ETL MapReduce
Hadoop-23 Sqoop 数据MySQL到HDFS(部分) SQL生成数据 HDFS集群 Sqoop import jdbc ETL MapReduce
52 0
|
2月前
|
SQL 分布式计算 关系型数据库
Hadoop-22 Sqoop 数据MySQL到HDFS(全量) SQL生成数据 HDFS集群 Sqoop import jdbc ETL MapReduce
Hadoop-22 Sqoop 数据MySQL到HDFS(全量) SQL生成数据 HDFS集群 Sqoop import jdbc ETL MapReduce
60 0
|
4月前
|
SQL druid Java
Java数据库部分(MySQL+JDBC)(二、JDBC超详细学习笔记)(下)
Java数据库部分(MySQL+JDBC)(二、JDBC超详细学习笔记)
65 3
Java数据库部分(MySQL+JDBC)(二、JDBC超详细学习笔记)(下)

相关实验场景

更多