热门搜索 :
考研考公
您的当前位置:首页正文

java+swing+mysql图书管理系统(附完整源代码)

来源:伴沃教育
课程设计精品图书If理系统

书生

系统说明:本系统釆用eclipse开发,IDEA, eclipse, myedipse均可运行 界面采用swing实现

数据库:mysql.附sql代码,其余数据库可复制sql代码运行 数据库连接文件 mysql-connector-java-8.0.16.jar 本系统的背景图片可根据自己的需求替换 项目分为管理员和普通用户两种角色

管理员有图书査询、图书借还、账户管理(修改密码、账户信息、借书记录)、图书管理 (増加、修改、删除)的权限

普通用户有图书査询、图书借还、账户管理(修改密码、借书记录)的权限

项目结朴

-温图书系饨

>,JRE 基绽库(JavaSE-12] IS src y .[« Dao

> dZl AdminDao.java > ® BookDao.java > <2)BorrowDao.java > I/) DB.java

> El LandDao.java v SB Test

> JZ) LandTest.java 击 View

> ABorrowBookFace.java 通 AccountMsgFacejava > i£\\ AddBookFace.java > (2 AdminFace.java

> Lfi BookAdminFace.java > ® BookReturnFace.java > Si BookSearc h Fac e.java > DeleteBookFace.java > JZ) LogonFace.java > Si MainFace.java

> JZl UBorrowBookFace.java > <2)UpdateBookFace.java > UpdatePswFace.java > E) UserFace.java > i引用的阵 y 4 datebase

圍 tsglsys.sql 〜〜img

。admin.jpeg 。bg1.jpg 。login.jpg —mainbg.jpg y — lib

耳 mysql-connector-java-8.0.16.jar

登录界面:

管理员登录:蘇号root,密码123123 普通用户登录:账号123,密码123123

2

注册界面:

管理员主界面: E W ill

W

图书査询界面,

fflHW

3

I 齐血 IM BA* MKftW

图书查训

讷逸拝査询方式: y松■.

图书借还界面,

| w ・ IMKA* WIHIH- 图书借还

埔输入书号,

检室

竹名: 作帝 状妇 ifc«

账户管理界面:

图书管理界面:

添加图书界面:

图书管理

*MNHCa WAIVKGU M&NIISGft

添加图书

类别:膑弄类琳

书名: ______________ 2J 作者: 出版社: 价格:

确定

修改图书界面:

修改图书信息

15 ■;: I 类别:页逸择晒 书名: 作者: 出版社: 状态:。馆 价格:

确定

账户值息界面:

AH5记录界面:

账户信息

诱盗拝A

改方式:

借书记录

普通用户主界面:

普通用户際户管理界面:

背景图片,

账户管理

8

9

数据库文件(tsglsys.Sql): SET NAMES utf8mb4;

SET FOREIGN_KEY_CHECKS = 0; DROP TABLE IF EXISTS bookcategory*; CREATE TABLE 'bookcategory' (

'Category' varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 1 类别‘,

PRIMARY KEY ('Category') USING BTREE

)ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW.FORMAT = Compact;

INSERT INTO 'bookcategory' VALUES ('军事'); INSERT INTO 'bookcategory' VALUES ('天文'); INSERT INTO 'bookcategory' VALUES ('学术'); INSERT INTO 'bookcategory' VALUES ('小说'); INSERT INTO 'bookcategory' VALUES ('文艺'); INSERT INTO 'bookcategory' VALUES ('科幻'); INSERT INTO 'bookcategory' VALUES ('经济‘); DROP TABLE IF EXISTS booktable,;

10

CREATE TABLE 'booktable' (

'bookid' int(10) NOT NULL AUTOJNCREMENT COMMENT'书号‘,

'category' varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT ' 类别', 'bookname' varchar(lOO) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT'书名,, author' varchar(2O) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT'作者,

'press' varchar(lOO) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT'出版社,

price' float(10, 2) NOT NULL COMMENT'价格

'state' varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMEN「状态 PRIMARY KEY ( bookid*) USING BTREE, INDEX 'category'('category') USING BTREE,

CONSTRAINT 'booktable_ibfk_l* FOREIGN KEY ('category') REFERENCES 'bookcategory' ( Category*) ON DELETE RESTRICT ON UPDATE CASCADE

)ENGINE = InnoDB AUTOJNCREMENT = 21 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW.FORMAT = Compact;

INSERT INTO 'booktable VALUES (1,,学术。'《JAVA程序设计教程》*,'刘志宏航空工业出版 社)45.00,在馆,);

INSERT INTO 'booktable* VALUES (2,,学术〉,《软件工程》‘,'程成'机械工业出版社',31.50, * 在馆‘);

INSERT INTO 'booktable' VALUES (3,'学术* (计算机文化》'(美)帕森斯(Parsons JJf,'电子工 业出版社28.00,,在馆》;

INSERT INTO 'booktable' VALUES (4,,文艺〉'《我在未来等你》','刘同','青年光影出版社 36.50,,在馆‘);

INSERT INTO 'booktable' VALUES (5,'小说,《西游记》'吴承恩'岳麓出版社33.50,,在馆,); INSERT INTO 'booktable* VALUES (6,'学术'《数据结构(c语言)》\\ '严蔚敏清华大学出版 社\"27.50,,在馆,);

11

INSERT INTO 'booktable' VALUES (7, ,学术。 INSERT INTO 'booktable VALUES (8,'学术《计算机文化基础》,,'李永红','对外经济贸易大 学。32.50,在馆,);

INSERT INTO'booktable'VALUES (9, ,学术J《数据库系统实现》/加西亚-莫利纳‘机械工 业出版社',47.00, ,在馆》;

INSERT INTO 'booktable' VALUES (10,,文艺,'《数据库系统基础教程》'厄尔曼'机械工业出 版社。38.50,,在馆');

INSERT INTO 'booktable* VALUES (11,'学术 J《数学思维导论》‘Keith Devlin1,'人民邮电出版 枇40.00,,在馆)

INSERT INTO 'booktable' VALUES (12,'学术‘《移动应用Ul设计必修课》‘,'余振华'人民邮 电出版社36.00,,在馆');

INSERT INTO 'booktable' VALUES (13,,学术,《快速软件开发》,史蒂夫•迈克康奈尔,,‘清华 大学出版社*, 25.50/在馆,);

INSERT INTO 'booktable' VALUES (14,,科幻 J《三体》‘刘慈欣‘重庆出版社31.00,,在馆 INSERT INTO booktable* VALUES (15, ,科幻,,'《海底两万里》\\ ,镭尔•凡尔纳,,'译林出版社 32.50,,在馆

INSERT INTO 'booktable' VALUES (16,'军事‘《狼牙》'刘猛'北京联合出版公司35.50,,在 馆》; INSERT INTO ,booktable' VALUES (17,'天文'《宇宙的琴弦》'布赖恩•格林','湖南科学技术 岀版社。30.00,,在馆

INSERT INTO booktable VALUES (18,'经济,,'《货币经融学》'弗宙德里克・S•米什金'中国人 民大学出版社60.00/在馆》;

1

1

DROP TABLE IF EXISTS 'borrowrecords'; CREATE TABLE 'borrowrecords* (

'id' int(10) NOT NULL AUTOJNCREMENT COMMEN「借书序列‘,

'user' varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '用户 名, 'bookid' int(10) NOT NULL COMMENT '书号‘,

'bookname' varchar(SO) CHARACTER SETutf8 COLLATE utf8_general_ci NOT NULL COMMENT, 书名',

12

'borrowtime' date NOT NULL COMMENT ‘借书时间',

'returntime* date NULL DEFAULT NULL COMMENT1 还书时间',

'status' varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '状 态: PRIMARY KEY ('id') USING BTREE

)ENGINE = InnoDB AUTOJNCREMENT = 25 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW.FORMAT = Compact;

DROP TABLE IF EXISTS 'usertable*; CREATE TABLE 'usertable* (

'user' varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '用户 名,, 'studentid' varchar(2O) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT 1 学号‘, 'name' varchar(2O) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT名 I

'password* varchar(2O) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT ' 密码', admin' int(10) NOT NULL COMMENT 否为管理员账户1为管理员,0为普通用户,耿 认为0', PRIMARY KEY ('user') USING BTREE

)ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW.FORMAT = Compact;

13

user studentid name password admin

「123

|123 123 123123 0 j 1234 1234 1234 123123 0 root

root

root

123123

1

INSERT INTO 'usertable' VALUES ('123', '123', '123', '123', 0); INSERT INTO 'usertable' VALUES ('root*, 'root*, 'root*, '123', 1); SET FOREIGN_KEY_CHECKS = 1;

ft®库表g

bookid 3c9oprew

♦■■n字术

《JAVAft序釦球询孩

换2现出版吐

2 k <«nze>

E工业出加 3字术 《计・叔化》

伊DgXPgom J“坦孑工业出如t

4 ftZ MR

■年光彫出或吐

Category

6K 《EM构(cms)

即恩

砂大竽岀版牡

7字术 8任厦綺地大孕岀阪牡 0

字术 EH奶.t»;已狰

9字术

9M1

対咄疥倒月大学

tC®E WW SlMIlkttitttt

10 J7X 《以»5翌3砲 娅厄尔JI BUHk 出 CM

学术11字术 《蚊学专姥号沦〉

Keith Devtin

入印曲出扱吐

12字天 人出版吐

13学术

14冲 <=»)

或庆岀wt

15 瞬史》

版壮 科幻16

旅合出版公5)

17S9叔 《芥&3蜘

布1鴨花协

18竖济

中国人抵裂蛔之

id user bookid bookname borrowtime

returntime 27 1234 13《快速软件开发2019-12-25 2019-12-25

28 root

1 CJAVA^yiSv 2019-12-25

Dao 包下的 AdminDao.java:

package Dao; import java.sql.*;

import javax.swing.DOptionPane; public class AdminDao

14

price Udtc 45.00 汛1 3150 StS 2800 STB 3&5O StS 3150 E 27.SE 40.00 E® 32.50 E 47.00 m 3a 50 E 40.00 m 3600 ZBB 25.50 E 31.00 ®S 32-SOEm 35.SO 3000 阪 60.00 &i

status 已还

public static boolean sureuser(String user) {

Connection con = DB .connectDBO; PreparedStatement preSql; ResultSet rs;

String sqlStr = \"select * from usertable where user = ?\" try {

preSql = con.prepareStatement(sqlStr); preSql.setString(l, user); rs = preSql.executeQuery(); boolean flag = false; while(rs.next()) {

flag = true; return true; ) if(!flag) (

return false; )

con.close(); return false; } catch (SQLException e) (

return false; })

public static void modifypass(String user,String password)

Connection con = DB.connectDB();

15

PreparedStatement preSql;

String sqlStr = \"update usertable set password=? where user = ?\"; try {

preSql = con.prepareStatement(sqlStr); preSql.setString(l, password); preSql.setString(2, user); int ok = preSql.executeUpdate(); con.close(); ) catch (SQLException e) { }}

public static Boolean adduser(String user, String studentid, String name. String password) (

Connection con = DB.connectDB(); PreparedStatement preSql;

String sqlStr = \"insert into usertable values (?,?,?,?,0)\"; try {

preSql = con.prepareStatement(sqlStr); preSql.setString(1, preSql.setstring(2, preSql.setString(3, preSql.setString(4,

int ok = preSql.executeUpdate(); con.close(); return true;

} catch (SQLException e) (

user); studentid); name); password);

JOptionPane.shoivMessageDiatog(null,\"用户名已存在\"' 警告\",

DOptionPane.MARNING_MESSAGE);

16

return false; )

}}

BookDao.java:

package Dao; import java.sql.*; import java.util.*; import javax.swing.*;

import javax.swing.table.Default!ableModel; public class BookDao {

public BookDao() { }

public static void findcategory(JComboBox box) (

Connection con = DB.connectDBO; PreparedStatement preSql; ResultSet rs;

String sqlStr = \"select * from bookcategory\"; try {

preSql = con.prepareStatement(sqlStr); rs = preSql.executeQuery();

17

while (rs.next()) {

String category = rs.getString(l); box.addltem(category);

con.close(); } catch (SQLException e) (

〃添加图书

public static void addbook(String category,String bookname,String author,String press,String price) {

Connection con = DB.connectDB(); PreparedStatement preSql; String sqlStr = \"insert into

booktable(category,bookname,author,press,price,state) values

try {

preSql = con.prepareStatement(sqlStr); preSql.setString(l, preSql.setstring(2, preSql.setString(3, preSql.setString(4, preSql.setString(5,

category); bookname); author); press); price);

preSql.setString(6, ”在馆”);

int ok = preSql.executeUpdate();

18

con.close(); ) catch (SQLException e) { }} 〃修改图书

public static void modifybook(int bookid,String category,String bookname,String author,String press,String state,String price) (

Connection con = DB.connectDB(); PreparedStatement preSql;

String sqlStr = \"update booktable set category = ?

,bookname = ? ,author = ?,press = ? ,price = ?,state = ? where bookid =

try {

preSql = con.prepareStatement(sqlStr); preSql.setString(l, preSql.setstring(2, preSql.setString(3, preSql.setString(4, preSql.setString(5, preSql.setstring(6,

preSql.setlnt(7, bookid); int ok = preSql.executeUpdate(); con.close();

) catch (SQLException e) { }) 〃删除图书

public static void deletebook(int bookid) {

Connection con = DB .connectDBO;

19

category); bookname); author); press); price); state);

PreparedStatement preSql;

String sqlStr = \"delete from booktable where bookid = ?\" try {

preSql = con.prepareStatement(sqlStr); preSql.setInt(l, bookid); int ok = preSql.executeUpdate(); con.close(); } catch (SQLException e) ( })

//显示所有图书

public static void allbook(DefaultTableModel model) {

Connection con = DB.connectDB(); PreparedStatement preSql; ResultSet rs;

String sqlStr = \"select * from booktable\"; try {

preSql = con.prepareStatement(sqlStr); rs = preSql.executeQuery(); while (rs.next()) {

int bookid = rs.getlnt(l); String category = rs.getString(2);

String bookname = rs.getString(3); String author = rs.getString(4); String press = rs.getString(5); String price = rs.getString(6);

20

String state = rs.getString(7);

model.addRow(new Vector。(Arrays.assist(bookid, category, bookname, author,

press,price, state)));

)

con.close(); ) catch (SQLException e) ( }}

//按类别査找图书

public static void findcategory(DefaultTableModel model. String CateGory) {

Connection con = DB.connectDB(); PreparedStatement preSql; ResultSet rs; CateGory =

+ CateGory + \"%”;

String sqlStr = \"select * from booktable where category like ?\"; try {

preSql = con.prepareStatement(sqlStr); preSql.setString(l, CateGory); rs = preSql.executeQuery(); boolean flag = false; while (rs.next()) {

flag = true;

int bookid = rs.getlnt(l); String category = rs.getString(2); String bookname = rs.getString(3); String author = rs.getString(4); String press = rs.getString(5);

21

String price = rs.getString(6); String state = rs.getString(7);

model.addRow(new Vectoro(Arrays.asList(bookid, category, bookname, author, press,

price,state)));

} if Sag) {

DOptionPane. shoMMessageDia Log (null,\"图书不存在

\警告\",JOptionPane.UARNING_MESSAGE');

)

con.close(); ) catch (SQLException e) ( }}

//按书号查找图书

public static void findbookid(DefaultTableModel model, int Bookid) (

Connection con = DB.connectDB(); PreparedStatement preSql; ResultSet rs;

String sqlStr = \"select * from booktable where bookid try {

preSql = con.prepareStatement(sqlStr); preSql.setInt(l, Bookid);

rs = preSql.executeQuery(); boolean flag = false; while (rs.next()) (

flag = true;

int bookid = rs.getlnt(l); String category = rs.getString(2); String bookname = rs.getString(3); String author = rs.getString(4);

22

String press = rs.getString(S); String price = rs.getString(6); String state = rs.getString(7);

model.addRow(new Vector<>(Arrays.as£ist(bookid,

category, bookname, author, press, price,state)));

} if (!flag) (

JOptionPane. showMessageDia Log (null,\"图书不存在

\警告”,JOptionPane.UARNING_MESSAGE);

)

con.close();

} catch (SQLException e) {

BorrowDao.java

package Dao; import java.sql.*; import java.sql.Date; import java.util.*;

import javax.swing.table.Default!ableModel; public class BorrowDao {

public BorrowDao() { }

〃借阅图书

public static void Borrow(String user, int bookid. String bookname) {

23

Connection con = DB.connectDB(); PreparedStatement preSql;

String sqlStr = \"insert into borrowrecords(user,bookid,bookname,borrowtime,returntime,statu s) values

(?,?,?,now(),null,?)\";

try {

preSql = con.prepareStatement(sqlStr); preSql.setString(l, user); preSql.setInt(2, bookid); preSql.setString(3, bookname);

preSql.setString(4,\"未还”);

int ok = preSql.executeUpdate(); con.close();

ChangeBorrouState(bookid); } catch (SQLException e) { }}

〃借阅图书修改图书状态

private static void ChangeBorrowState(int bookid) {

Connection con = DB .connectDBQ; PreparedStatement preSql;

String sqlStr = \"update booktable set state=? where bookid = ?\"; try {

preSql = con.prepareStatement(sqlStr); preSql.setString(l, ”外借”); preSql.setlnt(2, bookid); int ok = preSql.executeUpdate();

24

con.close(); ) catch (SQLException e) { }} 〃还书

public static void Return(String user, int bookid) {

Connection con = DB.connectDB(); PreparedStatement preSql; String sqlStr = \"select now()\"; ResultSet rs; Date date=null; try {

preSql = con.prepareStatement(sqlStr); rs = preSql.executeQuery(); while(rs.next()) {

date = rs.getDate(l); )

sqlStr = \"update borrowrecords set returntime = ? where bookid = ? and user = ? and status = ?\"; preSql = con.prepareStatement(sqlStr); preSql.setDate(l, date); preSql.setlnt(2, bookid); preSql.setString(3, user);

preSql.setString(4,\"未还”);

int ok = preSql.executeUpdate();

sqlStr = \"update borrowrecords set status = ? where bookid = ? and user = ? and status = ?\"; preSql = con.prepareStatement(sqlStr);

25

preSql.setString(l,\"已还”);

preSql.setlnt(2, bookid); preSql.setstring(3, user);

preSql.setString(4,\"未还”); ok = preSql.executeUpdate(); con.close();

ChangeReturnState(bookid); } catch (SQLException e) { })

〃还书图书修改图书状态

private static void ChangeReturnState(int bookid) {

Connection con = DB.connectDB(); PreparedStatement preSql;

String sqlStr = \"update booktable set state=? where bookid = ?\"; try {

preSql = con.prepareStatement(sqlStr);

preSql.setString(l,\"在馆”);

preSql.setInt(2, bookid); int ok = preSql.executeUpdate(); con.close(); } catch (SQLException e) ( }} 〃比对还书

public static boolean comparison(String user,int bookid) {

26

Connection con = DB.connectDB(); PreparedStatement preSql; ResultSet rs;

String sqlStr = \"select * from borrowrecords where bookid = ? and status = ?\"; try {

preSql = con.prepareStatement(sqlStr); preSql.setInt(l, bookid);

preSql.setString(2,\"未还”);

rs = preSql.executeQuery(); while (rs.next()) {

String user2 = rs.getString(2); if(user2.equals(user)) {

return true; )else {

return false; }} con.close(); return false; ) catch (SQLException e) {

return false; })

public static void allborrow(DefaultTableModel model) (

Connection con = DB.connectDB(); PreparedStatement preSql; ResultSet rs;

String sqlStr = \"select * from borrowrecords\";

27

try ( preSql = con.prepareStatement(sqlStr); rs = preSql.executeQuery();

while (rs.next()) {

String user = rs.getString(2); int bookid = rs.getlnt(3);

String bookname = rs.getString(4); Date date = rs.getDate(5); Date date2 = rs.getDate(6); String status = rs.getString(7); model.addRow(new

Vector<>(Arrays.asList(user,bookid,bookname,date,date2,status))) ;}

con.close(); ) catch (SQLException e) { }}

〃用户名借书记录

public static void userborrow(DefaultTableModel model,String user) {

Connection con = DB.connectDB(); PreparedStatement preSql; ResultSet rs;

String sqlStr = \"select * from borrowrecords where user

=?”;

try {

preSql = con.prepareStatement(sqlStr); preSql.setString(1, user); rs = preSql.executeQuery(); while (rs.next()) {

int bookid = rs.getlnt(3);

28

String bookname = rs.getString(4); Date date = rs.getDate(5); Date date2 = rs.getDate(6); String status = rs.getString(7); model.addRow(new

Vector<>(Arrays.asList(user,bookid,bookname,date,date2,status))) ;}

con.close(); } catch (SQLException e) ( })

//书号借书记录

public static void bookidborrow(DefaultTableModel model,int bookid) (

Connection con = DB.connectDB(); PreparedStatement preSql; ResultSet rs;

String sqlStr = \"select * from borrowrecords where

bookid =

try {

preSql = con.prepareStatement(sqlStr); preSql.setInt(l, bookid); rs = preSql.executeQuery(); while (rs.next()) {

String user = rs.getString(2); String bookname = rs.getString(4); Date date = rs.getDate(5); Date date2 = rs.getDate(6);

29

String status = rs.getString(7); model.addRow(new

Vector<>(Arrays.asList(user,bookid,bookname,date,date2,status))) ;}

con.close();

} catch (SQLException e) {}

})

DB.java(数据库连接类):

package Dao; import java.sql.*; public class DB {

public static Connection connectDB() {

String url = \"jdbc:mysql://

localhost:3306/tsglsys?sepverTimezone=GMT%2B8\";

try {

Class ./orA/ame(\"com.mysql. cj .jdbc. Driver\"); } catch (Exception e) ( }

Connection con = null;

try {

con = DriverManager.getConnection(url, \"root\

\"1234\");

} catch (SQLException e) ( } return con; }}

30

LandDao.java:

package Dao; import java.sql.*;

import javax.swing.JOptionPane; public class LandDao (

public static Boolean test(String user. String password) (

Connection con = DB.connectDB(); PreparedStatement preSql; ResultSet rs;

String sqlStr = \"select * from usertable where user = ?\" try {

preSql = con.prepareStatement(sqlStr); preSql.setString(l, user); rs = preSql.executeQuery(); boolean flag = false; while(rs.next()) {

flag = true;

String password2 = rs.getString(4); if (!(password.equals(password2))) {

DOptionPane. shoMMessageDia Log (null,\"密码错误

\"警告\",JOptionPane .UARNING_MESSAGE);

return false;}}

if(!flag) (

JOptionPane. showMessageDia Log (null,\"用户名不存在\"'

31

\"警告\JOptionPane.UARNING_MESSAGE);

return false; )

con.close(); return true;

) catch (SQLException e) {

JOptionPane. showMessageDia Log (null,\"用户名不存在\"'\"

警告”,JOptionPane .MARNING_MESSAGE);

return false; }}

〃确定是否为管理员

public static boolean sureadmin(String user) {

Connection con = DB.connectDB(); PreparedStatement preSql; ResultSet rs;

String sqlStr = \"select * from usertable where user = ?\" try {

preSql = con.prepareStatement(sqlStr); preSql.setString(l, user); rs = preSql.executeQuery();

while(rs.next()) {

int admin = rs.getlnt(5); if (admin==l) {

return true;

32

)else {

return false;

}}

con.close(); return true;

) catch (SQLException e) {

return false;

})}

Test 包 LandTest.java:

package Test; import java.awt.*;

import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; import Dao.LandDao; import View.LogonFace; import View.MainFace; public class LandTest {

private JLabel jLabel = new J Label (\"图书管理系统”);

33

private DLabel jLabel2 = new 3Label(\"用户名:\");

private DLabel jLabel3 = new 3Label(\"密 码:”);

private Font font = new Font(\"宋体Font.BOLD, 40); private Font font2 = new Font(\"宋体”,Font.BOLD, 25); private Font font3 = new Font(\"宋体\",Font.SOLD, 20); private DTextField field = new 3TextField(22);

private DPasswordField field2 = new 3PasswordField(22);

private JButton button = new J Button (\"登陆”);

private JButton button2 = new JButton(\"注册”);

private private private private

3Panel JPanel JPanel JPanel JPanel

jPanel = new JPanel(); jPanel2 = new jPanel3 = new jPanel4 = new jPanelS = new

JPanel(); 3Panel(); JPanel(); 3Panel();

private

private JFrame frame = new J Frame (\"登陆”);

private Dimension dimension = new Dimension(30, 30);

private Dimension dimension2 = new Dimension(100, 50); public String user; private String password; public LandTest() {

frame .setTitle(\"登陆”);

frame.setSize(550, 500);

frame.setLocationRelativeTo(null);

35

frame.setLayout(null);

Toolkit t = Toolkit.getDefauLtTooLkit^; Image image = t.getlmage(\"img\\\\login.jpg\"); frame.seticonimage(image); addassembly(); transparent(); addEvent();

Icon i = new Imageicon(\"img\\\\login.jpg\"); JLabel Label = new JLabel(i); Label.setBounds(0, 0, 550, 500); frame.add(Label); frame.setResizable(false);

frame. setDef aultCloseOperation (J F name. EXIT_ON_CLOSE'); frame.setVisible(true);} private void addassembly() {

jLabel.setFont(font); j Label2.setFont(font2); j Label3.setFont(font2); button.setFont(font3); buttonZ.setFont(font3); field.setFont(font3); field2.setFont(font3);

field.setPreferredSize(dimension); field2.setPreferredSize(dimension); button.setPreferredSize(dimension2);

button2.setPreferredSize(dimension2); jPanel.add(jLabel);

35

jPanel2.add(jLabel2); jPanel2.add(field); jPanel3.add(jLabel3); jPanel3.add(field2); jPanel4.add(button); jPanels.add(button2);

jPanel.setBounds(0, 60, 550, 80); jPanel2.setBounds(0, 160, 550, 80); jPanel3.setBounds(0, 250, 550, 60);

jPanel4.setBounds(100, 325, 150, 80); jPanel5.setBounds(275, 325, 150, 80); fname.add(jPanel); frame.add(jPanel2); frame.add(jPanel3); frame.add(jPanel4); frame.add(jPanelS);} private void transparent() (

jLabel.setOpaque(false); jLabel2.setOpaque(false); jLabel3.setOpaque(false); field.setOpaque(false); field2.setOpaque(false); jPanel.setOpaque(false); jPanel2.setOpaque(false); jPanel3.setOpaque(false); jPanel4.setOpaque(false); jPanel5.setOpaque(false);) private void addEvent() {

button.addActionListener(new ActionListener() {

36

public void actionPerformed(ActionEvent e) {

user = field.getText().trim(); password = field2.getText(); if(LandDao.test(user, password)) {

DOptionPane. shoMMessageDia Log (null f \"登陆成功”);

frame.dispose(); new MainFace(user); )else {

empty。; }}

});

button2.addActionListener(new ActionListener() (

public void actionPerformed(ActionEvent e) (

frame.dispose(); new LogonFace();)

}); }

private void empty() {

field. setText(,,H); field2.setText(\"”); }

public static void main(String[] args) (

new LandTest(); }}

37

View 包 ABorrowBookFace.java:

package View; import java.awt.*; import java.awt.event.*; import java.util.Vector; import javax.swing.*; import javax.swing.table.*; import Dao.BorrowDao;

public class ABorrowBookFace extends JFrame (

private DPanel jPanel = new JPanel();

private DLayeredPane jLayeredPane = new 3LayeredPane(); private JLabel jLabel = new J Label (\"借书记录”);

private JLabel jLabel2 = new JLabel(,f请选择査询方式:“); private DTextField field = new 3TextField(20);

private 3ComboBox box = new 3ComboBox(); private JButton button = new JButton(\"搜索”); private Font font = new Font(\"宋体”,Font.BOLD, 40);

38

private Font font2 = new private Font font3 = new private Font font4 = new

Font(\"宋体“,Font.BOLD, 20); Font(\"宋体\",Font.SOLD, 18); Font(“宋体\",Font.BOLD, 17);

model = new DefaultTableModel();

public DefaultTableModel

private String s; private int num;

public ABorrowBookFace() {

Icon i = new Imageicon(\"img\\\\bgl.jpg\"); JLabel Label = new JLabel(i);

Label.setBounds(0, 0, 850, 100); setLayout(null); setSize(850, 65。); setLocationRelativeTo(null); jLabel.setFont(font);

j Label.setBounds(345, 80, 400, 100); j Label2.setFont(font4);

jLabel2.setBounds(95, 140, 250, 30); box. additem (“按照用户名查找”);

box. additem (”按照书号査找”);

box.setFont(font3);

box.setBounds(95, 175, 160, 30); box.setOpaque(false); field.setFont(font2);

field.setBackground(Color.cyan);

39

field.setBounds(325, 175, 200, 30); field.setOpaque(false); button.setFont(font2);

button.setBounds(590, 173, 80, 35); button.setBackground(Color.cyan); button.setOpaque(false); jPanel.add(jLabel); jPanel.add(jLabel2); jPanel.add(box); jPanel.add(field); jPanel.add(button);

model.addColumn(\"用户名\new Vector());

model.addColumn(\"书号\new Vector()); model. addColumn(\"书名”,new Vector

());

model.addColumn(\"借书日期\new Vector()); model.addColumn(\"还书日期”,new

Vector());

model.addColumn(\"状态\new Vector());

JTable jTable = new 3Table(model);

JScrollPane pane = new JScrollPane(jTable); pane.setBounds(80, 220, 690, 340); jLayeredPane.add(pane); BorrowDao.aLLborrou^model);

setTitle(\"借书记录“);

40

setResizable(false); addEvent();

JTableHeader head = jTable.getTableHeader(); head.setPreferredSize(new Dimension(head.getWidth(),

30));

head.setFont(new Font(\"宋体\",Font.BOLD, 20)); head.setBackground(Color.cyan); jTable.setRowHeight(30);

jTable.setFont(new Font(”宋体”,Font.ROMAN_BASELINEf 17));

DefaultTableCellRenderer renderer = new

DefaultTableCellRenderer();

renderer.setHorizontalAlignment(DefaultTableCellRenderer.C£ NTER);

jTable.setDefaultRenderer(Object.class, renderer); jPanel.setBounds(0, 0, 850, 250); jPanel.setOpaque(false); jPanel.setLayout(null); setContentPane(jLayeredPane); add(jPanel); add(Label); setVisible(true); }

private void addEvent() (

s =\"按照用户名査找”;

box.addItemListener(new ItemListener() {

public void itemStateChanged(ItemEvent e) {

if (e.getStateChange() == ItemEvent.SELECTED) ( s = (String) e.getltem();

41

}}

});

button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { model.setRowCount(O);

if (s.equals(”按照用户名査找\")){

try (

String user = field.getText().trim(); BorrowDao.userborrow(model, user); ) catch (Exception el) {

}

} else if (s.equals(”按照书号查找”)){

try {

num =

Integer.parselnt(field.getText().trim());

BorrowDao.bookidborrou^model, num); ) catch (Exception el) {}) field. setText(^,,,);

}});

})

AccountMsgFace.java:

package View; import java.awt.*; import java.sql.*; import java.util.*;

42

import javax.swing.*; import javax.swing.table.*; import Dao.DB;

public class AccountMsaFace extends JFrame {

private DPanel jPanel = new JPanel();

private DLayeredPane jLayeredPane = new 3LayeredPane(); private J Label j Label = new J Label (\"账户信息\");

private Font font = new Font(\"宋体”'Font.BOLD, 40); public DefaultTableModel model = new DefaultTableModel(); public AccountMsgFace() {

Icon i = new Imagelcon(\"img\\\\bgl.jpg\"); JLabel Label = new JLabel(i); Label.setBounds(0, 0, 800, 100); setLayout(null); setSize(800, 600);

setLocationRelativeTo(null); jLabel.setFont(font);

jLabel.setBounds(315, 80, 400, 100); jPanel.add(jLabel);

model.addColumn(\"用户名\new Vector());

model.addColumn(\"学号new Vector()); model.addColumn(\"姓名\new Vector());

model.addColumn(\"是否为管理员\",new Vector());

DTable jTable = new JTable(model); JScrollPane pane = new JScrollPane(jTable);

43

pane.setBounds(80, 160, 640, 350); jLayeredPane.add(pane);

JTableHeader head = jTable.getTableHeader(); head.setPreferredSize(new Dimension(head.getWidth(),

30));

head.setFont(new Font(\"宋体\",Font.BOLD, 20)); head.setBackground(Color.cyan); jTable.setRowHeight(30);

jTable.setFont(new Font(“宋体\",Font.ROMAN_BASELINE, 17));

DefaultTableCellRenderer renderer = new

DefaultTableCellRenderer();

renderer.setHorizontalAlignment(DefaultTableCellRenderer.C£ NTER);

jTable.setDefaultRenderer(Object.class; renderer); borrow(model);

jPanel.setBounds(0, 0, 800, 200); jPanel.setOpaque(false); jPanel.setLayout(null); setContentPane(jLayeredPane);

setTitleC* 账户信息“);

setResizable(false); add(jPanel); add(Label); setVisible(true); }

private void borrow(DefaultTableModel model) (

44

Connection con = DB .connectDBO; PreparedStatement preSql; ResultSet rs;

String sqlStr = \"select * from usertable\"; try {

preSql = con.prepareStatement(sqlStr); rs = preSql.executeQuery(); while (rs.next()) (

String user = rs.getString(l); String studentid = rs.getString(2); String name = rs.getString(3); int flag = rs.getlnt(S); String admin; if (flag == 1) (

admin =”是\"; ) else {

admin =\"否“; )

model.addRow(new Vector<>(Arrays.as£ist(user, studentid, name, admin))); )

con.close(); } catch (SQLException e) ( )

}}

AddBookFace.java:

package View;

45

import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.table.*; import Dao.BookDao;

public class AddBookFace extends JFrame( private DPanel jPanel = new 3Panel();

private DLabel jLabel = new J Label (\"添加图书\");private JLabel jLabel2 = new JLabel(\"类 另!j :\");

private JLabel jLabel3 = new JLabel(\"书 名:\");

private JLabel jLabel4 = new JLabel(\"作 者:”); private

JLabel jLabelS = new JLabel(\"出版社:\");

46

private JLabel jLabel6 = new 3Label(\"价格:\"); private private private private private

JTextField DTextField DTextField JTextField

field = new 3TextField(20); field2 = new field3 = new field4 = new

JTextField(20); 3TextField(20); JTextField(20);

new 3ComboBox();

3ComboBox box =

private JButton button = new 3Button(\"确定”); private Font font = new Font(\"宋体Font.fiOLD, 40); private Font font2 = new Font(\"宋体\ private

Font font3 = new

Font(” 宋体”,

public DefaultTableModel model = new DefaultTableModel(); private String s; public AddBookFace() (

Icon i = new Imagelcon(\"img\\\\bgl.jpg\"); JLabel Label = new JLabel(i); Label.setBounds(0, 0, 580, 100); setLayout(null); setSize(580, 650);

setTitle(\"添加图书”);

setLocationRelativeTo(null); jLabel.setFont(font);

jLabel.setBounds(195, 80, 400, 100); j Label2.setFont(font2);

jLabel2.setBounds(125, 200, 250, 30); j Labels.setFont(font2);

jLabel3.setBounds(125, 260, 250, 30); j Label4.setFont(font2);

47

Font.BOLD, 25);Font.BOLD, 20);

jLabel4.setBounds(125, 320, 250, 30); jLabel5.setFont(font2); jLabel5.setBounds(125, 380, 250, 30); j Label6.setFont(font2);

jLabel6.setBounds(125, 440, 250, 30); box. additem (\"请选择类别\"); BookDao. findcategory (box); box.setFont(font3);

box.setBounds(245, 200, 200, 30); box.setOpaque(false); field.setFont(font3);

field.setBackground(Color.cyan);

field.setBounds(245, 260, 200, 30); field.setOpaque(false); field2.setFont(font3);

field2.setBackground(Color.cyan); field2.setBounds(245, 320, 200, 30); field2.setOpaque(false); fields.setFont(font3);

field3.setBackground(Color.cyan); field3.setBounds(245, 380, 200, 30); field3.setOpaque(false);

48

field4.setFont(font3);

field4.setBackground(Color.cyan); field4.setBounds(245, 440, 200, 30); field4.setOpaque(false); button.setFont(font2);

button.setBounds(120, 515, 325, 35); button.setBackground(Color.cyan); button.setOpaque(false); jPanel.add(jLabel); jPanel.add(jLabel2); jPanel.add(jLabel3); jPanel.add(jLabel4); jPanel.add(jLabels); jPanel.add(jLabel6); jPanel.add(box); jPanel.add(field); jPanel.add(field2); jPanel.add(field3); jPanel.add(field4); jPanel.add(button); add();

jPanel.setBounds(0, 0, 850, 650); jPanel.setOpaque(false); jPanel.setLayout(null); add(jPanel); add(Label);

49

setResizable(false); setVisible(true); }

public void setModel(DefaultTableModel model) (

this.model = model; }

private void add() {

s =\"请选择类别”;

box.addItemListener(new ItemListener() (

public void itemStateChanged(ItemEvent e) (

if(e.getStateChange()==ItemEvent.SELECTED) { s=(String)e.getItem();

}}

});

〃添加搜索按钮事件

button.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

String bookname = field.getText().trim(); String author = field2.getText().trim(); String press = field3.getText().trim(); String price = field4.getText().trim();

BookDao.addbook(s, bookname, author, press,price); model.setRowCount(0);

50

BookDao. at Lhoo/?( model);

JOptionPane. showMessageDia Log (null,\"操作成功”); }});

}}

AdminFace.java:

package View; import java.awt.*; import java.awt.event.*; import javax.swing.*; import Test.LandTest; public class AdminFace {

public DPanel jPanel2 = new JPanel();

private 3Label jLabel = new 3Label(\"账户管理\");

private ^Button button2 new 3Button (\"修改密码\");

private JButton button? new JButton(\"借书记录”);

private JButton button4 new J Button (\"退出登陆”);

private ^Button buttons new JButton(\"账户信息\");

private Font font = new Font (\"宋体”'Font .BOLD, 60); private Font fontl = new Font(\"宋体\Font.BOLD, 25); private String user; private DFrame frame; public AdminFace() {

51

Icon i = new ImagelconC'imgWadmin.jpeg\"); JLabel Label = new JLabel(i); Label.setBounds(0, 0, 1200, 800); jPanel2.setLayout(null); jLabel.setFont(font);

j Label.setBounds(460, 50, 800, 70); button2.setFont(fontl); button3.setFont(fontl); button4.setFont(fontl); buttons.setFont(fontl); button2.setBounds(460, 200, button3.setBounds(460, 270, buttons.setBounds(460, 340, button4.setBounds(460, 410,

250, 250, 250, 250,

50); 50); 50); 50);

button2.setBackground(Color.cyan); buttons.setBackground(Color.cyan); buttons.setBackground(Color.cyan); add(); button2.setOpaque(false); buttons.setOpaque(false);

button4.setOpaque(false); buttons.setOpaque(false); jPanel2.add(button?); j Panel2.add(button3);

button4.setBackground(Color.cyan);

jPanel2.add(button4); jPanel2.add(buttons); jPanel2.add(jLabel); jPanel2.add(Label); }

52

public void setUser(String user) {

this.user = user; }

public void setFrame(3Frame frame) (

this.frame = frame; }

private void add() (

button2.addActionListener(new ActionListener() (

public void actionPerformed(ActionEvent e) {

UpdatePswFace password = new UpdatePswFace(user); password.setFrame(fname);}

});

button3.addActionListener(new ActionListener() (

public void actionPerformed(ActionEvent e) {

new ABorrowBookFace();}

});

button4.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

frame.dispose(); new LandTest();} });

buttons.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new AccountMsgFace();}

}); }}

53

BookAdminFace.java:

package View; import java.awt.*; import java.awt.event.*; import javax.swing.*;

import javax.swing.table.Default!ableModel; public class BookAdminFace {

public DPanel jPanel2 = new JPanel();

private JLabel jLabel = new J Label (\"图书管理”);

private JButton button = new J Button (\"添加图书信息”);

private ^Button button2 = new JButton(\"修改图书信息”);

private J Button button? = new J Button (\"删除图书信息”);

private Font font = new Font(\"宋体Font .BOLD, 60); private Font fontl = new Font(\"宋体”,Font .BOLD, 25); public DefaultTableModel model = new DefaultTableModel(); public BookAdminFace() {

Icon i = new Imageicon(\"img\\\\bgl.jpg\"); JLabel Label = new JLabel(i); Label.setBounds(0, 0, 1200, 800); jPanel2.setLayout(null); jLabel.setFont(font);

j Label.setBounds(460, 50, 800, 70); button.setFont(fontl); buttonZ.setFont(fontl); buttons.setFont(fontl);

button.setBounds(460, 200, 250, 50); buttonZ.setBounds(460, 300, 250, 50); button?.setBounds(460,

54

400, 250, 50);

button.setBackground(Color. cyan);

button2.setBackground(Color.cyan); buttons.setBackground(Color.cyan); button.setOpaque(false); button2.setOpaque(false); buttons.setOpaque(false); add();

jPanelZ.add(button); jPanel2.add(button?); jPanel2.add(button3); jPanel2.add(jLabel); jPanel2.add(Label);

public void setModel(DefaultTableModel model) {

this.model = model; }

private void add() {

button.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) (

AddBookFace addBook = new AddBookFace。; addBook.setModel(model);}

});

button2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {

UpdateBookFace modifyBook = new UpdateBookFace(); modifyBook.setModel(model);}

});

buttons.addActionListener(new ActionListener() (

public void actionPerformed(ActionEvent e) {

55

DeleteBookFace deleteBook = new DeleteBookFace(); deleteBook.setModel(model);}

}); }}

BookReturnFace.java:

package View; import java.awt.*; import java.awt.event.*;

56

import java.sql.*; import javax.swing.*;

import javax.swing.table.DefaultTableModel; import Dao.BookDao; import Dao.BorrowDao; import Dao.DB;

public class BookReturnFace {

public DLayeredPane jLayeredPane = new JLayeredPane(); private DPanel jPanel = new 3Panel(); private

JLabel

jLabel = new J Label (\"图书借还\");

private DLabel jLabel2 = new J Label (”请输入书号:“);

private JLabel jLabel3 = new JLabel(\"书名:”);

private private private

JLabel 3Label JLabel

jLabel4 = new jLabelS = new jLabel6 = new

JLabel();

3Label(M作者:“); JLabel();

private JLabel jLabel? = new JLabel(\"状态:”);

private JLabel jLabels = new 3Label();

private JLabel jLabel9 = new

JLabel(M书号:”);

private private

JLabel jLabell0 = new JLabel();

DTextField field = new 3TextField(20);

private ^Button button = new JButton(\"检索”);

private ^Button button2 = new JButton(\"还书”);

private ^Button button3 = new JButton(\"借阅”);

private Font font = new Font(\"宋体“,Font.BOLD, 60);

57

private Font font2 = new Font(\"宋体\",Font.BOLD, 30); private Font font3 = new Font(\"宋体“,Font.BOLD, 26); private String user;

private Default!ableModel model = new DefaultTableModel(); int id; public BookReturnFace() {

Icon i = new Imagelcon(\"img\\\\bgl.jpg\"); JLabel Label = new JLabel(i); Label.setBounds(0, 0, 1200, 800); jLabel.setFont(font);

jLabel.setBounds(480, 35, 800, 100); j Label, set Foreground (Color, bloc/?); jLabelZ.setFont(font2);

jLabelZ.setBounds(280, 164, 250, 30); jLabel2.setForeground(Color.bLack); field.setFont(font2);

field.setBackground(Color.black); field.setBounds(480, 164, 250, 30); field.setForeground(Color.btacfe); field.setopaque(false);

button.setFont(font2);

button.setBounds(780, 160, 100, 40);

button.setForeground(Color.b£acfe); button.setBackground(Color.bLack); button.setOpaque(false); jPanel.setBounds(270, 220, 620, 450); jPanel.setBackground(Color.white); jPanel.setLayout(null); jLabel3.setFont(font2); jLabel4.setFont(font2);

58

jLabels.setFont(font2); j Labels.setFont(font2); jLabel?.setFont(font2); jLabels.setFont(font2); jLabel9.setFont(font2); jLabell0.setFont(font2);

button2.setFont(font3); buttons.setFont(font3);

jLabel3.setForeground(Color.bLack); jLabel4.setForeground(Color.btacfe); jLabels.setForeground(Color.bLack); jLabel7.setForeground(Color.dtacfe); jLabels.setForeground(Color.bLack);

jLabel9.setForeground(Color.btacfe);

jLabel6.

set

Foreground

(Color,

btac/?);

jLabe!10.setForeground(Color .btac/?); button2.setForeground(Color.bLack);

59

buttons. setForeground (Color. bLack'); jLabel9.setBounds(100, 20, 100, 50); jLabell©.setBounds(200, 20, 400, 50); j Label?.setBounds(100, jLabel4.setBounds(200, j Labels.setBounds(100, j Label6.setBounds(200, jLabel?.setBounds(100, j Labels.setBounds(200,

90, 100, 50); 90, 400, 50); 160, 160, 230, 230,

100, 400, 100, 400,

50); 50); 50); 50);

button2.setBounds(80, 310, 90, 50); button3.setBounds(460, 310, 90, 50); button2.setBackground(Color.bLack); button2.setOpaque(false); button3.setBackground(Color.bLack); button3.setOpaque(false); addEvent(); jPanel.add(jLabel3); jPanel.add(jLabel4); jPanel.add(jLabels); jPanel.add(jLabel6); jPanel.add(jLabel?); jPanel.add(jLabels); jPanel.add(jLabel9);

jPanel.add(jLabellQ); jPanel.add(button2);

jPanel.add(button3); jPanel.setOpaque(false);

jLayeredPane.add(Label, new Integer(0), 0); jLayeredPane.add(jLabel, new . 1); jLayeredPane.add(jLabel2, new 1供, 2);

60

jLayeredPane.add(field, new , 3); jLayeredPane.add(button, new Integer(10。),4); jLayeredPane.add(jPanel, new 1代所如(10。),5); }

public void setUser(String user) {

this.user = user; }

public void setModel(DefaultTableModel model) {

this.model = model; }

private void addEvent() {

button.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) { try {

id = Integer.parselnt(field.getText().trim()); field. setText(\",,); Connection con = DB.connectDB(); PreparedStatement preSql; ResultSet rs;

String sqlStr = \"select * from booktable where

try {

preSql = con.prepareStatement(sqlStr); preSql.setlnt(l, id); rs = preSql.executeQuery(); boolean flag = false; while (rs.next()) (

flag = true;

jLabell0.setText(rs.getStning(l));

61

jLabel4.setText(rs.getString(3)); jLabel6.setText(rs.getString(4)); jLabels.setText(rs.getString(7)); } if (!flag) (

JOptionPane .showMessageDia Log (null,\"图书 不存在\",\"警告\",

JOptionPane .NARNING_MESSAGE);

empty。; )

con.close();

) catch (SQLException el) ( }} catch (Exception el) (

JOptionPane.sho^MessageDiaLog(null,\"输入不正确

\警告”,JOptionPane.h/ARI\\IING_MESSAGE);

field. setTextC,\"); }}

62

});

button3.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

if (j Labels. get Text (). equals (\"在馆”)){

id =

Integer .parselnt( jLabellO.getText() .trim。);

BorrowDao.Borrow^user, id, j Label4.getText().trim());

DOptionPane.showMessageDiaLog^null,”借阅成功!

\恭喜\",JOptionPane.UARNING_MESSAGE');

empty();

model.setRowCount(O); BookDao. at Ldoo/?( model);

) else if (jLabels.getText().equals(\"外借”)){

DOptionPane. shoMMessageDia Log (null,\"此书已经借 出去了哦!

\",JOptionPane.MARNING_MESSAGE);

empty(); } else {

”警告

JOptionPane. showMessageDia Log (null,\"错误!\警告”,JOptionPane.

MARNING_MESSAGE);

}}

});

button2.addActionListener(new ActionListener() (

public void actionPerformed(ActionEvent e) (

if (jLabels.getText().equals(\"外借\"))(

64

if(BorrowDao.comparison(user, id)) { id =

Integer.parselnt(jLabellO.getText().trim()); BorrowDao.Return(user, id);

JOptionPane.showMessageDiaLog(null,\"还书成”);

empty();

model.setRowCount(0);

BookDao.成比。ok(model);

}else (

JOptionPane. showMessageDia Log (null,\"此书不 是您借的哦!\",DOptionPane.MARNING_MESSAGE);

}

) else if (jLabels.getText().equals(\"在馆”)){

JOptionPane.showMessageDiaLog(null,\"此书在馆哦!

\\"警告”,JOptionPane.UARNING_MESSAGE');

empty。; } else {

JOptionPane.showMessageDiaLog(null,\"错误! H

,\" 警告

\JOptionPane.MARNING_MESSAGE);

}}

});} public void empty() (

jLabel4. set Text (\"•'); jLabel6.setText(\"\");

64

,\"恭喜

\"jLabels.setText(\"”); jLabell0.setText(\"\"); }}

BookSearchFace.java:

package View; import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; import javax.swing.table.*; import Dao.BookDao; public class BookSearchFace {

public DLayeredPane jLayeredPane = new 3LayeredPane(); private JLabel jLabel = new J Label (\"图书查询\");

private JLabel jLabel2 = new J Label (\"请选择查询方式:”);

private DTextField field = new 3TextField(25);

private Dimension dimension = new Dimension(220, 30); private 3ComboBox box = new 3ComboBox(); private JButton button = new 3Button(\"搜索”);

public DefaultTableModel model = new DefaultTableModel(); private Font font = new Font(\"宋体

Font .BOLD, 60); private Font fontl = new Font(\"宋体”,Font.BOLD, 25); private Font font2 = new Font(\"宋体\",Font.BOLD, 20); private String s;

private String book; private int id;

public BookSearchFace() {

Icon i = new Imagelcon(\"img\\\\bgl.jpg\");

65

JLabel Label = new JLabel(i); Label.setBounds(0, 0, 1200, 800); jLabel.setFont(font);

jLabel.setBounds(485, 35, 800, 100); jLabel.setForeground(Color.btacfe); jLabel2.setFont(fontl);

jLabelZ.setBounds(180, 130, 250, 30); jLabel2.setForeground(Color.bLack); //下拉框

box.setSize(dimension);

box. additem (“按照类别查找\");

box. additem (”按照书号查找\");

box.setFont(font2);

box.setBounds(180, 170, 200, 40); box.setOpaque(false); field.setFont(font2); field.setsize(dimension);

field.setBackground(Color.bLack); field.setBounds(480, 173, 250, 35); field.setForeground(Color.bLack);

66

field.setOpaque(false); button.setFont(fontl);

button.setBounds(850, 170, 100, 40); button.setForeground(Color.btacfe); button.setBackground(Color.gray):

button.setOpaque(false) model.

new Vector()); new

addColumn (\"书号\model. addColumn

Vector()); new Vector());

(\"类别\model.addColumn(\"书名\

new Vector());

model. addColumn (\"作者\model.

addColumn (\"出版社' model.

,new Vector()); new Vector()); new

addColumn (\"价格\model. addColumn

Vector());

(\"状态\

JTable jTable = new 3Table(model); JScrollPane pane = new JScrollPane(jTable); pane.setBounds(180, 250, 800, 400); BookDao. at L boo/? (model);

JTableHeader head = jTable.getTableHeader(); head.setPreferredSize(new Dimension(head.getWidth(),

30));

head.setFont(new Font(\"宋体”,Font.SOLD, 20)); head.setBackground(Color.gray); jTable.setRowHeight(30);

jTable.setFont(new Font(”宋体”,Font.ROMAN_BASELINEt 17)); DefaultTableCellRenderer renderer = new

DefaultTableCellRenderer();

renderer.setHorizontalAlignment(DefaultTableCellRenderer.C£ NTER);

67

jTable.setDefaultRenderer(Object.class, renderer); addEvent();

jLayeredPane.add(Label, new Integer(0). 0); jLayeredPane.add(jLabel, new Integer(10。),1); jLayeredPane.add(jLabel2, new , 2);

jLayeredPane.add(box, new Integer(1。。),3); jLayeredPane. add (field, new , 4); jLayeredPane.add(button, new Integer(10。),5); j LayeredPane. add (pane, new . 6); }

private void addEvent() {

s = ”按照类别查找”;

box.addItemListener(new ItemListener() (

public void itemStateChanged(ItemEvent e) (

if(e.getStateChange()==ItemEvent.SELECTED) (

s=(String)e.getItem(); }}

});

button.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) { model.setRowCount(0);

if(s.equals(“按照类别查找“)){ book=field.getText().trim();

BookDao.findcategory(model, book); }else if(s.equals(M按照书号査找”))( try {

68

id=

Integer.parselnt(field.getText().trim());

BookDao.findbookid(model, id); )catch(Exception el) { }}

field. setText(,,,,);}

});

})

DelectBookFace.java:

package View; import java.awt.*; import java.awt.event.*; import javax.swing.*;

import javax.swing.table.DefaultTableModel; import Dao.BookDao;

public class DeleteBookFace extends DFrame (

private DPanel jPanel = new JPanel();

69

private DLabel jLabel = new 3Label(\"书号:\");

private JLabel jLabel2 = new JLabel(\"删除图书”);

private private private private private

DTextField field Font font2 = new Font font3 = new Font font4 = new DButton button =

=new 3TextField(22); Font(\"宋体\",Font.BOLD, Font(”宋体”,Font.BOLD, Font(\"宋体”,Font.BOLD, new JButton(\"确 定\");

model = new DefaultTableModel();

18); 40);

public DefaultTableModel public DeleteBookFace() {

setSize(400, 450);

setTitle(\"删除图书”);

Icon i = new Imageicon(\"img\\\\bgl.jpg\"); JLabel Label = new JLabel(i); Label.setBounds(0, 0, 400, 100); jLabel.setFont(font2); field.setFont(font3); button.setFont(font3); jLabel2.setFont(font4);

jLabel2.setBounds(100, 110, 200, 60); jLabel.setBounds(55, 210, 100, 30); field.setBounds(140, 210, 185, 28);

button.setBounds(47, 300, 288, 35); addEvent();

jPanel.add(jLabel2); jPanel.add(jLabel);

70

jPanel.add(field); jPanel.add(button); jPanel.setLayout(null);

jPanel.setBounds(0, 0, 600, 400); jPanel.setOpaque(false); add(jPanel); add(Label); setResizable(false); setLocationRelativeTo(null); setLayout(null); setVisible(true);}

public void setModel(DefaultTableModel model) { this.model = model; }

private void addEvent() {

button.addActionListener(new

ActionListener()

{

actionPerformed(ActionEvent e) { try {

int bookid =

Integer.parselnt(field.getText().trim());

BookDao.deletebook(bookid); model.setRowCount(0); BookDao.allbook(model);

71

public

void

DOptionPane. showMessageDialog(null,\"操作成功”); ) catch (Exception el) { }} }); })

LoginFace.java:

package View;

import import import import import public

java.awt.*; java.awt.event.* ; javax.swing.*; Dao.AdminDao; Test.LandTest; class LogonFace {

JLabel

jLabel = new 3Label(\"注 册”);

private

private JLabel jLabel2 = new JLabel(\"用户名:”);

private private

JLabel 3Label

jLabel3 = new jLabel4 = new

DLabelC1 学 3Label(\"姓

号:”); 名:“)

private JLabel jLabelS = new JLabelC, 密 码:“);

private JLabel jLabel6 = new JLabel (”确认密码:”);

private

JLabel jLabel? = new JLabelC*

密码长度:6~16位,不能含有空格“);

private String user; private String studentid;

72

private String name; private String password;

String password2; private

Font font = new Font(\"宋体”,Font.BOLD, 40) private

Font font2 new Font(”宋体”,Font.BOLD, 25); private

Font font3 private new Font(\"宋体”,Font.BOLD, 20);

private Font font4 new Font(\"小篆\",Font.ITALIC, 13);

private

private

private private

private private private

private private

private private private

private

private private private

private

Font

fonts

new field

Font(“宋体\",Font.BOLD, 17); =new 3TextField(18);

DTextField DTextField DTextField

field2 = new JTextFieId(18); field3 = new JTextField(18);

JPasswordField field4 = new JPasswordField(18); DPasswordField fields = new 3PasswordField(18); ^Button button = new JButton(\"注册\"); ^Button button2 = new 3Button(\"返回“); Dimension dimension = new Dimension(350, 40); JPanel JPanel JPanel JPanel JPanel JPanel JPanel DFrame

jPanel = new 3Panel(); jPanel2 = new jPanel3 = new jPanel4 = new jPanel5 = new jPanel6 = new jPanel? = new

3Panel(); JPanel(); 3Panel(); JPanel(); JPanel(); 3Panel();

frame = new 3Frame(\"注册”);

public LogonFace() {

73

frame.setSize(450, 580); frame.setLayout(null);

frame.setLocationRelativeTo(null); Toolkit t = Toolkit.getDefauLtTooLkitO; Image image = t.getlmage(nimg\\\\bgl.jpg\"); frame.setlconlmage(image); addassembly(); transparent(); addEvent();

Icon i = new Imagelcon(\"img\\\\login.jpg\"); 3Label Label = new JLabel(i); Label.setBounds(0, 0, 450, 547); fname.add(Label); frame.setResizable(false);

frame.setDefaultCloseOperation(JFname.EXIT_ON_CLOSE); frame.setVisible(true); }

private void addassembly() {

jLabel.setFont(font); jLabel2.setFont(font2); jLabel3.setFont(font2); jLabel4.setFont(font2); j Labels.setFont(font2); jLabel6.setFont(font2); jLabel7.setFont(font4);

74

jLabel?.setForeground(Color.red); j Label.setBounds(170, 30, 150, 60); button.setFont(font2); field.setFont(font3); field2.setFont(font3); field3.setFont(font3); field4.setFont(font3); fields.setFont(font3);

field.setForeground(Color.blue);

field2.setForeground(Color.btue); fields.setForeground(Color.btue); field4.setForeground(Color.blue); fields.setForeground(Color.btue); button.setPreferredSize(dimension); buttonZ.setFont(font5); button2.setBounds(2, 2, 70, 30); button2.setBackground(Color.cyan); button2.setOpaque(false); jPanel.add(button2); jPanel.add(jLabel); jPanel2.add(jLabel2); jPanel2.add(field); jPanel3.add(jLabel3); jPanel3.add(field2); j Panel4.add(j Label4); jPanel4.add(field3); jPanel5.add(jLabels); jPanel5.add(field4); jPanel5.add(jLabel?); jPanel6.add(jLabel6); jPanel6.add(fields); jPanel?.add(button); jPanel.setLayout(null);

jPanel.setBounds(0, 0, 450, 110); jPanel2.setBounds(0, 110, 450, 50); jPanel3.setBounds(0, 180, 450, 50);

75

jPanel4.setBounds(0, jPanel5.setBounds(0, jPanel6.setBounds(0,

jPanel7.setBounds(0,

frame.add(jPanel);

fname.add(jPanel2); frame.add(jPanel3); frame.add(jPanel4); frame.add(jPanels); frame.add(jPanel6); frame.add(jPanel?); }

private void transparent() {

jLabel.setOpaque(false);

jLabel2.setOpaque(false); jLabel3.setOpaque(false); jLabel4.setOpaque(false); jLabel5.setOpaque(false); jLabel6.setOpaque(false); field.setOpaque(false); field2.setOpaque(false); field3.setOpaque(false); field4.setOpaque(false); fields.setOpaque(false); jPanel.setOpaque(false); jPanel2.setOpaque(false);

250, 450, 50); 320, 450, 70); 390, 450, 50); 460,

450, 60);

76

jPanel3.setOpaque(false); jPanel4.setOpaque(false); jPanel5.setOpaque(false); jPanel6.setOpaque(false); jPanel6.setOpaque(false); jPanel7.setOpaque(false); }

private void addEvent() {

button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { user = field.getText().trim();

studentid = field2.getText().trim(); name = field3.getText().trim(); password = field4.getText().trim(); password? = fields.getText() .trimQ; if (user.length() == 0) (

JOptionPane.shouMessageDiaLog^null,\"用户名不能

为空”,\"警告\",JOptionPane.UARNING_MESSAGE);

empty。;

) else if (studentid.length() == 0) {

JOptionPane.shoMMessageDiaLog(null,”学号不能为 空“,\"警告”,

JOptionPane.MARNING_MESSAGE');

empty。;

} else if (name.length() == 0) {

JOptionPane. shouMessageDia Log (null,\"姓名不能为 空\",\"警告”,

77

JOptionPane.MARNING_MESSAGE);

empty();

} else if (password.length() < 6 |

password.length() > 12) {

JOptionPane. shouMessageDia Log (null,\"密码输人不 正确\",\"警告\",

JOptionPane.MARNING_MESSAGE);

empty。;

} else if (!(password.equals(password2))) (

JOptionPane. shouMessageDia Log (null,\"两次输入密

码不相同”,”警告”,JOptionPane.NARNING_MESSAGE);

empty。;

} else ( if (AdminDao.oddt/ser(user, studentid, name.

password))

JOptionPane. shoMMessageDia Log (null t \"注册成 功”); frame.dispose(); new LandTest(); } else {

empty(); }})

});

button2.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

frame.dispose(); new LandTest(); }});}

private void empty() {

78

field. setText(^,,,); field2.setText(\"”); field3. setText(,,H); field4.setText (\ fields. setText(■,,,); }}

MainFace.java:

package View; import java.awt.*; import javax.swing.*; import Dao.LandDao;

public class MainFacc extends 3Frame{

public DTabbedPane jTabbedPane = new JTabbedPane(); private DPanel jPanel = new JPanel();

private J Label jLabel = new J Label (\"欢迎登陆图书管理系统\");

private Font font = new Font(\"宋体Font .BOLD, 60);

private Font font2 = new Font(\"宋体”, Font.SOLD, 20); private Container con = getContentPane(); public MainFace(String user) (

Toolkit t = Toolkit.getDefauLtTooLkitO;

Image image = t.getlmage(\"img\\\\admin.jpeg\"); setlconlmage(image); Icon i = new Imagelcon(\"img\\\\admin.jpeg\"); JLabel Label = new JLabel(i); Label.setBounds(0, 0, 1200, 800); jPanel.setLayout(null); jLabel.setFont(font);

79

jLabel.setBounds(330, 50, 1000,200); jLabel. setForeground(Color.BMCK); jPanel.add(jLabel); jPanel.add(Label);

jTabbedPane.setFont(font2);

jTabbedPane.add(\"主 界 面”,jPanel);

BookSearchFace search = new BookSearchFace(); jTabbedPane. add (\"图书查询\search, j LayeredPane); BookReturnFace returning = new BookReturnFace(); returning.setUser(user); returning.setModel(search.model);

jTabbedPane.add(\"图书借还\returning.jLayeredPane);

if(LandDao.sureadmin(user)) {

AdminFace admin = new AdminFace(); admin.setUser(user); admin.setFrame(this);

jTabbedPane.add(\"账户管理”,admin.jPanel2);

BookAdminFace bookAdmin = new BookAdminFace(); bookAdmin.setModel(search.model);

jTabbedPane. add (\"图书管理\bookAdmin. j Panel2);

)else {

UserFace management = new UserFace(); management.setUser(user); management.setFrame(this);

jTabbedPane.add(\"账户管理”,management.jPanel2);

}

con.add(jTabbedPane);

80

setResizable(false);

setTitle(\"图书管理系统”);

81

setSize(1200, 800); setLocationRelativeTo(null); setVisible(true);

setDefaultClose0peration(3Frame.EXIT_ON_CLOSE);

})

UBorrowBookFace.java:

package View; import java.awt.*; import java.sql.*; import java.sql.Date; import java.util.*; import javax.swing.*; import javax.swing.table.*; import Dao.DB;

public class UBorrowBookFace extends JFrame {

private DPanel jPanel = new JPanel();

private DLayeredPane jLayeredPane = new 3LayeredPane(); private JLabel jLabel = new J Label (\"借书记录”);

private Font font = new Font(\"宋体”,Font.BOLD, 40); public DefaultTableModel model = new DefaultTableModel(); public UBorrowBookFace(String user) {

Icon i = new Imagelcon(\"img\\\\bgl.jpg\"); JLabel Label = new JLabel(i); Label.setBounds(0, 0, 800, 100);

83

setLayout(null); setSize(800, 600);

setLocationRelativeTo(null); jLabel.setFont(font);

jLabel.setBounds(315, 80, 400, 100); jPanel.add(jLabel);

model.addColumn(\"书号new Vector());

model. addColumn(\"书名new Vector ());

model.addColumn(\"借书日期\",new Vector());

model.addColumn(\"还书日期\new Vector());

model.addColumn(\"状态”,new Vector());

JTable jTable = new 3Table(model); JScrollPane pane = new 3ScrollPane(jTable); pane.setBounds(80, 160, 640, 350); jLayeredPane.add(pane);

JTableHeader head = jTable.getTableHeader();

head.setPreferredSize(new Dimension(head.getWidth(), 30)); head.setFont(new Font(\"宋体”,Font.SOLD, 20)); head.setBackground(Color. cyan); jTable.setRowHeight(30);

jTable.setFont(new Font(”宋体”,Font.ROMAN_BASELINEt 17));

DefaultTableCellRenderer renderer = new

DefaultTableCellRenderer();

83

renderer.setHorizontalAlignment(DefaultTableCellRenderer.C£ NTER);

jTable.setDefaultRenderer(Object.class, renderer); borrow(model, user);

jPanel.setBounds(0, 0, 800, 200); jPanel.setOpaque(false); jPanel.setLayout(null);

setTitle(\"借书记录”);

setResizable(false);

setContentPane(jLayeredPane); add(jPanel); add(Label); setVisible(true); }

private void borrow(DefaultTableModel model. String user) {

Connection con = DB.connectDB(); PreparedStatement preSql; ResultSet rs;

String sqlStr = \"select * from borrowrecords where user =?”; try {

preSql = con.prepareStatement(sqlStr); preSql.setString(l, user); rs = preSql.executeQuery(); boolean flag = false; while (rs.next()) (

flag = true;

84

int bookid = rs.getlnt(3);

String bookname = rs.getString(4); Date date = rs.getDate(5); Date date2 = rs.getDate(6); String state = rs.getString(7);

model.addRow(new Vector<>(Arrays.asList(bookid, bookname, date, date2, state)));} if (!flag) {

3Opt ionPane. showMessageDia Log (null,”您还没有借书哦!con.close();

) catch (SQLException e) { }}}

UpdateBookFace.java:

package View; import java.awt.*; import java.awt.event.*; import javax.swing.*;

import javax.swing.table.DefaultTableModel; import Dao.BookDao;

public class UpdateBookFace extends 3Frame(

85

\");}

private DPanel jPanel = new 3Panel();

private J Label jLabel = new J Label (\"修改图书信息”);

private JLabel jLabel2 = new JLabelC类 另lj :\");

private JLabel jLabel3 = new JLabel(M书名:”);

private JLabel jLabel4 = private JLabel jLabel5 = private JLabel jLabels =

new DLabelC作 者:”); new JLabel(-出版社:“); new JLabel(\"价格:”);

private JLabel jLabel6 = new JLabel(\"状态:”);

private JLabel jLabel?= new JLabel(M书 号:”);

private DTextField field =new 3TextField(20);

private DTextField field2 = new 3TextField(20); private DTextField field3 = new JTextField(20); private DTextField field4 = new 3TextField(20); private DTextField fields = new JTextField(20);

private 3ComboBox box = new 3ComboBox(); private 3ComboBox boxl = new JComboBox(); private DButton button = new 3Button(\"确定“); private Font font = new Font(\"宋体\",Font.BOLD, 40); private Font font2 = new private Font font3 = new public DefaultTableModel

Font(\"宋体\",Font.BOLD, 25); Font(\"宋体\",Font.BOLD, 20); model = new DefaultTableModel();

private String s;

private String si;

86

public UpdateBookFace() {

Icon i = new Imagelcon(\"img\\\\bgl.jpg\"); 3Label Label = new JLabel(i); Label.setBounds(0, 0, 580, 100); setLayout(null); setSize(580, 650);

setLocationRelativeTo(null);

setTitle(\"修改图书信息”);

jLabel.setFont(font);

jLabel.setBounds(155, 80, 400, 100); j Label?.setFont(font2);

jLabel7.setBounds(125, 200, j Label2.setFont(font2); jLabel2.setBounds(125, 250,

jLabel3.setFont(font2); jLabel?.setBounds(125, 300,

jLabel4.setFont(font2); jLabel4.setBounds(125, 350,

jLabels.setFont(font2); jLabels.setBounds(125, 400,

j Label6.setFont(font2); jLabel6.setBounds(125, 450,

jLabels.setFont(font2);

250, 250, 250, 250, 250, 250,

87

30);

30);

30);

30);

30);

30);

jLabel8.setBounds(125, 500, 250, 30); box • addltem(\"请选择类别\"); BookDao. findcategory (box'); box.setFont(font3);

box.setBounds(245, 250, 200, 30); box.setOpaque(false);

boxl.addltem(\"在馆”);

boxl. addltem(\"外借\"); BookDao.findcategory(box); boxl.setFont(font3);

boxl.setBounds(245, 450, 200, 30); boxl.setOpaque(false); field4.setFont(font3);

field4.setBackground(Color.cyan); field4.setBounds(245, 200, 200, 30); field4.setOpaque(false); field.setFont(font3);

field.setBackground(Color.cyan); field.setBounds(245, 300, 200, 30); field.setOpaque(false); field2.setFont(font3);

field2.setBackground(Color.cyan);

field2.setBounds(245, 350, 200, 30); field2.setOpaque(false);

88

fields.setFont(font3);

field3.setBackground(Color.cyan);

field3.setBounds(245, 400, 200, 30); field3.setOpaque(false); fields.setFont(font3);

fields.setBackground(Color.cyan); fields.setBounds(245, 500, 200, 30); fields.setOpaque(false); button.setFont(font2);

button.setBounds(120, 560, 325, 35); button.setBackground(Color.cyan); button.setOpaque(false); jPanel.add(jLabel); jPanel.add(jLabel2); jPanel.add(jLabel3); jPanel.add(jLabel4); jPanel.add(jLabels); jPanel.add(jLabel6); jPanel.add(jLabel?); jPanel.add(jLabels); jPanel.add(box); jPanel.add(boxl); jPanel.add(field); jPanel.add(field2); jPanel.add(field3);

89

jPanel.add(field4); jPanel.add(fieldS); jPanel.add(button); add();

jPanel.setBounds(0, 0, 850, 650); jPanel.setOpaque(false); jPanel.setLayout(null); setResizable(false); add(jPanel); add(Label); setVisible(true); }

public void setModel(DefaultTableModel model) {

this.model = model; }

private void add() {

s = ”请选择类别\";

box.addItemListener(new ItemListener() {

public void itemStateChanged(ItemEvent e) {

if(e.getStateChange()==ItemEvent.SE£ECr£D) {

s=(String)e.getItem(); }}});

si = “在馆”;

boxl.addItemListener(new ItemListener() (

public void itemStateChanged(ItemEvent e) (

if(e.getStateChange()==ItemEvent.S£L£C7£D) (

90

sl=(String)e.getItem();

}}

});

button.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

try {

String bookname = field.getText().trim(); String author = field2.getText().trim(); String press = field3.getText().trim();

String price = field4.getText().trim(); int bookid =

Integer .parselnt( fields. getText() .trim。);

BookDao.modifybook(bookid, s, bookname, author, press,price, si); model.setRowCount(0); BookDao. at Ldoo/?( model);

J0ptionPane.sA7owMessageDiaLog(null,\"操作成功”); }catch(Exception el)(

JOptionPane.showMessageDiaLog(null,\"输入不正确 \警告”,

JOptionPane.UARNING_MESSAGE);

}}

}); }}

91

UpdatePswFace.java:

package View; import java.awt.*; import j ava.awt.event.*; import java.sql.*; import javax.swing.*; import Dao.DB; import Test.LandTest;

public class UpdatcPswFace extends JFrame {

private DPanel jPanel = new JPanel();

private DLabel jLabel = new JLabel(\"用户名:”);

private 3Label jLabel2 new

JLabel();

private JLabel jLabel3 new

3Label(M原始密码:”);

private JLabel jLabel4 new

JLabel(\"新密码:“);

private JLabel jLabelS new

J Label (”确认密码:”);

private private

DPasswordField DPasswordField DPasswordField

field =new 3PasswordField(22);

field2 = new 3PasswordField(22); field3 = new 3PasswordField(22);

private

private Font font = new Font(\"宋体Font .BOLD, 24); private Font fontl = new Font(\"宋体”,Font.BOLD, 22); private JButton button = new 3Button(\"修 改\"); private DFrame frame = new 3Frame(); public UpdatePswFace(String user) {

setSize(600, 45。);

92

Icon i = new Imagelcon(\"img\\\\bgl.jpg\"); 3Label Label = new JLabel(i); Label.setBounds(0, 0, 600, 150);

setTitle(\"修改密码”);

jLabel2.setText(user); jLabel.setFont(font); j Label2.setFont(font); jLabel3.setFont(font); jLabel4.setFont(font); jLabelS.setFont(font); field.setFont(fontl); field2.setFont(fontl); field3.setFont(fontl); button.setFont(fontl); add();

jLabel.setBounds(120, 170, 150, 30); jLabel2.setBounds(260, 170, 300, 30); jLabel3.setBounds(120, 210, 150, 30); field.setBounds(260, 215, 140, 25);

jLabel4.setBounds(120, 250, 150, 30); field2.setBounds(260, 255, 140, 25); jLabel5.setBounds(120, 290, 150, 30);

field3.setBounds(260, 295, 140, 25); button.setBounds(115, 340, 285, 30); jPanel.add(jLabel); jPanel.add(jLabel2); jPanel.add(jLabel3); jPanel.add(field);

93

jPanel.add(jLabel4); jPanel.add(field2); jPanel.add(jLabels); jPanel.add(field3); jPanel.add(button); jPanel.setLayout(null);

jPanel.setBounds(0, 0, 600, 400); jPanel.setOpaque(false); add(jPanel); add(Label); setResizable(false); setLocationRelativeTo(null); setLayout(null); setVisible(true);}

public void setFrame(3Frame frame) (

this.frame = frame;}

private boolean comparison(String user. String password) (

Connection con = DB.connectDB(); PreparedStatement preSql; ResultSet rs;

String sqlStr = \"select * from usertable where user = try {

preSql = con.prepareStatement(sqlStr); preSql.setString(l, user); rs = preSql.executeQuery(); while (rs.next()) (

String s = rs.getString(4);

94

if (s.equals(password)) {

return true; } else (

return false; }} con.close(); return false; } catch (SQLException e) (

return false; }}

private void add() (

button.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

String user = jLabel2.getText().trim(); String oldpass = field.eetTextC).trim(); String newpass = f ield2. getTex^t (). trim(); String surepass = field3.fietText() .trimQ;

if (comparison(user, oldpass)) {

if(newpass.length()<6||newpass.length()>16) {

JOptionPane. showMessageDia Log (null,\"密码规 定 6-16 位,不能含有空

格\",\"警告\",JOptionPane.MARNING_MESSAGE');

empty。; }else (

if (newpass.equals(surepass)) {

95

Dao.AdminDao.modifypass(user, newpass); JOptionPane.

shoMHessageDia Log (null,\"修改成功”);

JOptionPane .shoMMessageDia Log (null,\"请重新登陆\");

dispose(); frame.dispose(); new LandTest(); )else {

DOptionPane.shoMMessageDiaLog(null,\"确认

密码不相同\",\"警告\",JOptionPane.UARNING_MESSAGE);

empty。; }}

} else (

JOptionPane.shoMMessageDiaLog(r\"p":{"h":14.525,"w":149.546,"x":356.835,"y":678.808,"z":47},"ps":null,"t":"wordf \"原始密码不JOptionPane.MARNING_MESSAGE);

empty。; }}

});)

96

正确\",\"警告\",

private void empty() ( field.setText(\"\"); field2.setText(\"”); field3. setText(');

}}

H,

UserFace.java:

package View; import java.awt.*; import java.awt.event.*; import javax.swing.*; import Test.LandTest;

public class UserFace

new JPanel();

public DPanel jPanelZ =

private DLabel jLabel = new J Label (\"账户管理”);

private DButton button2 new 3Button (\"修改密码\");

private JButton button? new JButton(\"借书记录”);

private JButton button4 new JButton(\"退出登陆\");

private Font font = new Font(\"宋体Font .BOLD, 60); private Font fontl = new Font(\"宋体”,Font.BOLD, 25); private String user;

private DFrame frame; public UserFace() {

Icon i = new Imagelcon(\"img\\\\bgl.jpg\"); 3Label Label = new 3Label(i); Label.setBounds(0, 0, 1200, 800); jPanel2.setLayout(null); jLabel.setFont(font);

jLabel.setBounds(460, 50, 800, 70); button2.setFont(fontl);

97

buttons.setFont(fontl); button4.setFont(fontl);

button2.setBounds(460, 200, 250, 50); buttons.setBounds(460, 300, 250, 50); button4.setBounds(460, 400, 250, 50);

button2.setBackground(Color.cyan); button3.setBackground(Color. cyan); button4.setBackground(Color.cyan); button2.setOpaque(false); button3.setOpaque(false); button4.setOpaque(false); add();

jPanel2.add(button2); jPanel2.add(buttons); j Panel2.add(button4); jPanel2.add(jLabel); jPanel2.add(Label);}

public void setUser(String user) {

this.user = user;}

public void setFrame(3Frame frame) {

this.frame = frame;} private void add() {

buttonZ.addActionListener(new ActionListener() (

public void actionPerformed(ActionEvent e) {

UpdatePswFace password = new UpdatePswFace(user); password.setFrame(frame); }});

button3.addActionListener(new ActionListener() (

98

public void actionPerformed(ActionEvent e) {

new UBorrowBookFace(user); }});

button4.addActionListener(new ActionListener() (

public void actionPerformed(ActionEvent e) {

frame.dispose(); new LandTest();}

}); }}

99

因篇幅问题不能全部显示,请点此查看更多更全内容

Top