本图书信息管理系统旨在提供一个直观的用户界面,用于管理图书馆或书店的图书信息。系统包括图书添加、查询、借阅和归还等功能。
系统采用JavaSwing作为前端UI框架,后端使用Java Servlet处理业务逻辑,数据存储在MySQL数据库中。
感谢提供数据库文件。以下是对这个数据库文件的简要说明:
book
表BookId
:图书ID,自增长。BookName
:图书名称。Writter
:作者。BookType
:图书类型。Price
:价格。IsBorrow
:是否借出。borrow
表BorrowId
:借阅记录ID,自增长。BookId
:借阅的图书ID。BookName
:借阅的图书名称。BookType
:借阅的图书类型。userid
:借阅者ID。username
:借阅者用户名。BorrowTime
:借阅时间。ReturnTime
:归还时间。IsReturn
:是否归还。root
表rootID
:管理员ID,自增长。rootName
:管理员用户名。rootPWD
:管理员密码。user
表userid
:用户ID,自增长。username
:用户名。userpsw
:用户密码。useremail
:用户邮箱。useraddr
:用户地址。userphone
:用户电话。这些表之间存在一些关联,比如 book
表和 borrow
表通过 BookId
关联。你可以使用这个数据库脚本初始化你的数据库。
Login.java
package view;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import utils.DBUtil;
public class LogIn extends JFrame {
private JLabel labTitle = new JLabel("图书信息管理系统登录");
private Font font = new Font("隶书", Font.BOLD, 34);
private JButton btnSure = new JButton("登录");
private JButton btnCancel = new JButton("重置");
private JButton btnZhuce = new JButton("注册");
private JPanel panBtn = new JPanel();
private JLabel labLoginName = new JLabel("用户名:");
private JLabel labPWD = new JLabel("密 码:");
private JTextField jtfLoginName;
private JPasswordField jpfPWD;
private JPanel panMain = new JPanel();
public LogIn() {
setTitle("登录界面");
// setDefaultLookAndFeelDecorated(true);
this.setSize(500, 350);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
init();
add(labTitle, BorderLayout.NORTH);
add(panBtn, BorderLayout.SOUTH);
add(panMain, BorderLayout.CENTER);
}
private void init() {
labTitle.setFont(font);
labTitle.setHorizontalAlignment(JLabel.CENTER);
labTitle.setForeground(Color.RED);
// labTitle.setBorder(BorderFactory.createLineBorder(Color.BLACK));
labTitle.setBackground(Color.BLUE);
// 单选框
JRadioButton JB1 = new JRadioButton("管理员登录");
JRadioButton JB2 = new JRadioButton("用户登录");
// 加入组,避免出现可以两个都选择的情况
ButtonGroup bg = new ButtonGroup();
JB2.setSelected(true);// 默认选中'用户登录'
jtfLoginName = new JTextField("", 10);
jpfPWD = new JPasswordField(16);
labLoginName.setSize(100, 40);
labLoginName.setLocation(50, 50);
labLoginName.setHorizontalAlignment(JLabel.RIGHT);
labPWD.setSize(100, 40);
labPWD.setLocation(50, 50 + 40 + 10);
labPWD.setHorizontalAlignment(JLabel.RIGHT);
jtfLoginName.setSize(200, 40);
jtfLoginName.setLocation(50 + 100 + 20, 50);
jpfPWD.setSize(200, 40);
jpfPWD.setLocation(50 + 100 + 20, 50 + 40 + 10);
jpfPWD.setEchoChar('*');
JB1.setSize(90, 20);
JB1.setLocation(125, 175);
JB2.setSize(80, 20);
JB2.setLocation(275, 175);
btnSure.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (JB2.isSelected()) {
Statement stmt = DBUtil.getStatement();
String name = jtfLoginName.getText().trim();
String pwd = new String(jpfPWD.getPassword()).trim();
String sql = "select * from user where username='" + name
+ "' AND userpsw='" + pwd + "';";
try {
ResultSet rs = stmt.executeQuery(sql);
if (rs.next()) {
JOptionPane.showConfirmDialog(LogIn.this,
"登陆成功,欢迎进入!", "登陆成功",
JOptionPane.CLOSED_OPTION);
dispose();
new LibraryUserFrame().setVisible(true);
LibraryUserFrame.USER_NAME = name;
} else {
JOptionPane.showMessageDialog(null, "账号或密码错误!");
}
} catch (SQLException e1) {
e1.printStackTrace();
}
/*
* UserDao UD = new UserDao(); UserBean uBean =
* UD.findUser(name, pwd); if (uBean != null) {
* JOptionPane.showConfirmDialog(LogIn.this, "登陆成功,欢迎进入!",
* "登陆成功", JOptionPane.CLOSED_OPTION); dispose();
* LibraryUserFrame LU = new LibraryUserFrame();
* LU.setVisible(true); LibraryUserFrame.USER_NAME = name;
* }else { JOptionPane.showMessageDialog(null, "账号或密码错误!");
* }
*/
} else {
Statement stmt = DBUtil.getStatement();
String name = jtfLoginName.getText().trim();
String pwd = new String(jpfPWD.getPassword()).trim();
String sql = "select * from root where rootName='" + name
+ "' AND rootPWD='" + pwd + "';";
try {
ResultSet rs = stmt.executeQuery(sql);
if (rs.next()) {
JOptionPane.showConfirmDialog(LogIn.this,
"登陆成功,欢迎进入!", "登陆成功",
JOptionPane.CLOSED_OPTION);
dispose();
LibraryRootFrame LR = new LibraryRootFrame();
LR.setVisible(true);
LibraryRootFrame.USER_NAME = name;
} else {
JOptionPane.showMessageDialog(null, "账号或密码错误!");
}
} catch (SQLException e1) {
e1.printStackTrace();
}
}
}
});
btnCancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
jtfLoginName.setText("");
jpfPWD.setText("");
}
});
btnZhuce.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
dispose();
new ZhuceFrame().setVisible(true);
}
});
panBtn.add(btnSure);
panBtn.add(btnCancel);
panBtn.add(btnZhuce);
// 把单选按钮加入组
bg.add(JB1);
bg.add(JB2);
panMain.setLayout(null);
panMain.add(labLoginName);
panMain.add(labPWD);
panMain.add(jtfLoginName);
panMain.add(jpfPWD);
panMain.add(JB1);
panMain.add(JB2);
ImageIcon img = new ImageIcon("image/ZhuCe.png");
// 要设置的背景图片
JLabel imgLabel = new JLabel(img);
// 将背景图放在标签里。
panMain.add(imgLabel, new Integer(Integer.MIN_VALUE));
// 将背景标签添加到jfram的LayeredPane面板里。
imgLabel.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());
// 设置背景标签的位置
Container contain = this.getContentPane();
((JPanel) contain).setOpaque(false);
}
public static void main(String[] args) {
new LogIn().setVisible(true);
}
}
LibraryUserFrame.java
package view;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
public class LibraryUserFrame extends JFrame {
public static String USER_NAME;
public LibraryUserFrame() {
this.setLayout(null);
ImageIcon img = new ImageIcon(
"image/3.jpg");
// 要设置的背景图片
JLabel imgLabel = new JLabel(img);
// 将背景图放在标签里。
this.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE));
// 将背景标签添加到jfram的LayeredPane面板里。
imgLabel.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());
// 设置背景标签的位置
Container contain = this.getContentPane();
((JPanel) contain).setOpaque(false);
setSize(1000, 750);
setTitle("图书馆管理系统_用户");
setResizable(false); // 不可改变窗口大小
// 获取屏幕大小和当前frame的大小
Dimension thisScreen = Toolkit.getDefaultToolkit().getScreenSize();
Dimension thisFrame = this.getSize();
// 使启动窗口位于屏幕的正中心
setLocation((thisScreen.width - thisFrame.width) / 2,
(thisScreen.height - thisFrame.height) / 2);
// 设置单击窗口的【关闭】按钮时将发生相应的动作
setDefaultCloseOperation(EXIT_ON_CLOSE);
JMenuBar menuBar = new JMenuBar(); // 创建菜单栏
// 创建菜单
JMenu j1 = new JMenu("书籍管理");
JMenuItem j1_1 = new JMenuItem("搜索图书");
j1_1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
new BookSearch().setVisible(true);
}
});
JMenuItem j1_2 = new JMenuItem("查看所有图书");
j1_2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
new AllBook().setVisible(true);
}
});
JMenuItem j1_3 = new JMenuItem("借阅图书");
j1_3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
new UserBorrow().setVisible(true);
}
});
JMenuItem j1_4 = new JMenuItem("归还图书");
j1_4.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
new UserReturn().setVisible(true);
}
});
j1.add(j1_1);
j1.add(j1_2);
j1.add(j1_3);
j1.add(j1_4);
JMenu j2 = new JMenu("个人中心");
JMenuItem j2_1 = new JMenuItem("修改密码");
j2_1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
new UserXiugaimima().setVisible(true);
}
});
j2.add(j2_1);
JMenu j3 = new JMenu("系统");
JMenuItem j3_1 = new JMenuItem("注销登录");
j3_1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
dispose();
new LogIn().setVisible(true);
}
});
j3.add(j3_1);
menuBar.add(j1);
menuBar.add(j2);
menuBar.add(j3);
this.setJMenuBar(menuBar);
}
}
LibraryRootFrame.java
package view;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import Date.BarTest;
import Date.PieChart;
import Date.PieTest;
public class LibraryRootFrame extends JFrame {
public static String USER_NAME;
public LibraryRootFrame() {
this.setLayout(null);
ImageIcon img = new ImageIcon("image/3.jpg");
//要设置的背景图片
JLabel imgLabel = new JLabel(img);
//将背景图放在标签里。
this.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE));
//将背景标签添加到jfram的LayeredPane面板里。
imgLabel.setBounds(0, 0, img.getIconWidth(), img.getIconHeight());
// 设置背景标签的位置
Container contain = this.getContentPane();
((JPanel) contain).setOpaque(false);
setSize(1000, 730);
setTitle("图书馆管理系统——管理员");
setResizable(false); // 不可改变窗口大小
// 获取屏幕大小和当前frame的大小
Dimension thisScreen = Toolkit.getDefaultToolkit().getScreenSize();
Dimension thisFrame = this.getSize();
// 使启动窗口位于屏幕的正中心
setLocation((thisScreen.width - thisFrame.width) / 2,
(thisScreen.height - thisFrame.height) / 2);
// 设置单击窗口的【关闭】按钮时将发生相应的动作
setDefaultCloseOperation(EXIT_ON_CLOSE);
JMenuBar menuBar = new JMenuBar(); // 创建菜单栏
// 创建菜单
JMenu j1 = new JMenu("书籍管理");
JMenuItem J1_1 = new JMenuItem("添加书籍");
J1_1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
new BookAddFrame().setVisible(true);
}
});
JMenuItem J1_2 = new JMenuItem("更新和删除书籍");
J1_2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
new Book_Update_Delete().setVisible(true);
}
});
JMenuItem J1_3 = new JMenuItem("查找书籍");
J1_3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
new BookSearch().setVisible(true);
}
});
JMenuItem J1_4 = new JMenuItem("查看所有书籍");
J1_4.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
new AllBook().setVisible(true);
}
});
j1.add(J1_1);
j1.add(J1_2);
j1.add(J1_3);
j1.add(J1_4);
JMenu j2 = new JMenu("用户管理");
JMenuItem J2_1 = new JMenuItem("添加用户");
J2_1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
new UserAddFrame().setVisible(true);
}
});
JMenuItem J2_2 = new JMenuItem("更新和删除用户");
J2_2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
new User_Update_Delete().setVisible(true);
}
});
JMenuItem J2_3 = new JMenuItem("查询用户");
J2_3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
new UserSearch().setVisible(true);
}
});
j2.add(J2_1);
j2.add(J2_2);
j2.add(J2_3);
JMenu j3 = new JMenu("借书记录");
JMenu J3 = new JMenu("借书数据分析");
JMenuItem J3_1 = new JMenuItem("饼形图查看");
J3_1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
new PieTest().setVisible(true);
}
});
JMenuItem J3_2 = new JMenuItem("条形图查看");
J3_2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
new BarTest().setVisible(true);
}
});
JMenuItem j3_1 = new JMenuItem("查看借书记录");
j3_1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
new AllBorrow().setVisible(true);
}
});
J3.add(J3_1);
J3.add(J3_2);
j3.add(J3);
j3.add(j3_1);
JMenu j4 = new JMenu("系统设置");
JMenuItem j4_1 = new JMenuItem("修改密码");
j4_1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
new RootXiugaiMima().setVisible(true);
}
});
JMenuItem j4_2 = new JMenuItem("注销登录");
j4_2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
dispose();
new LogIn().setVisible(true);
}
});
j4.add(j4_1);
j4.add(j4_2);
menuBar.add(j1);
menuBar.add(j2);
menuBar.add(j3);
menuBar.add(j4);
this.setJMenuBar(menuBar);
}
public static void main(String[] args) {
new LibraryRootFrame().setVisible(true);
}
}
q:969060742 文档、代码、sql