一、项目介绍
图书管理系统是一个常见的软件项目,广泛应用于图书馆、学校、企业等需要管理图书资源的场景。该系统通常涵盖图书信息录入、查询、借阅、归还等核心功能,是实现图书资源高效管理的重要工具。
随着信息技术的快速发展,传统纸质图书管理方式已经难以满足现代化管理的需求。图书管理系统的数字化转型成为当前图书馆和相关行业的重要发展方向。通过开发和应用图书管理系统,可以实现图书资源的数字化管理,提高工作效率,增强用户体验。
二、项目展示
登录界面
首页
读者查询
借阅图书
图书查询
三、源码展示
登录界面实现
public class LoginForm extends JFrame {
private JComboBox comboBox;
private JLabel title,usernamelab,passwordlab,select;
private JTextField usernameField;
private JPasswordField passwordField;
private JButton submit,updatePwd,regist;
private UserService service = new UserService();
public LoginForm() {
Container container = getContentPane();
container.setLayout(null);
submit=new JButton("登录");
submit.setBounds(20,210,60,20);
//登录监听
submit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
loginByUserAndPwd(e);
}
});
regist=new JButton("注册");
regist.setBounds(90,210,60,20);
//跳转到注册界面
regist.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
new RegistForm();
}
});
updatePwd=new JButton("修改密码");
updatePwd.setBounds(160,210,100,20);
//更新密码
updatePwd.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
new UpdatePwdForm();
}
});
title=new JLabel("图书管理系统");
title.setFont(new Font("宋体", Font.PLAIN, 24));
title.setBounds(70,30,200,25);
usernamelab=new JLabel("用户名:");
usernamelab.setFont(new Font("宋体", Font.PLAIN, 16));
usernamelab.setBounds(50,80,60,20);
passwordlab=new JLabel("密码:");
passwordlab.setFont(new Font("宋体", Font.PLAIN, 16));
passwordlab.setBounds(50,120,60,20);
usernameField=new JTextField();
usernameField.setBounds(120,80,130,20);
passwordField=new JPasswordField();
passwordField.setEchoChar('*');
passwordField.setBounds(120,120,130,20);
container.add(title);
container.add(usernamelab);container.add(usernameField);
container.add(passwordlab);container.add(passwordField);
container.add(submit);container.add(regist);container.add(updatePwd);
//container.setBackground(Color.RED);
setTitle("登录");
setSize(300,300);
setLocationRelativeTo(null);
setResizable(false);
setVisible(true);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
private void loginByUserAndPwd(ActionEvent e) {
String username = this.usernameField.getText();
String password = new String(this.passwordField.getPassword());
String is_admin="";
if(StringUtil.isEmpty(username)||StringUtil.isEmpty(password)){
JOptionPane.showMessageDialog(null,"用户名或密码不能为空");
}else {
is_admin="1";//管理员
User user = service.login(username, password, is_admin);
if (user!=null){
JOptionPane.showMessageDialog(null,"登录成功");
dispose();
new RootMainForm();
}else {
JOptionPane.showMessageDialog(null,"账号或面错误");
}
}
}
}
添加图书界面实现
public class AddBookForm extends JFrame {
private JLabel bookId,bookName,bookType,translator,publishTime,stock,price,publisher,author;
private JTextField bookIdField,bookNameField,translatorField,stockField,priceField,publisherField,authorField;
private JButton btn_Add,btn_Cancel;
private JComboBox<String> comboBox;
final JXDatePicker datepick = new JXDatePicker();
public AddBookForm(){
Container container = getContentPane();
container.setLayout(null);
btn_Add=new JButton("保存");
btn_Add.setBounds(190,310,80,20);
btn_Cancel=new JButton("取消");
btn_Cancel.setBounds(320,310,80,20);
//取消按钮监听
btn_Cancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
}
});
//添加按钮监听
btn_Add.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
addBook(e);
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
bookId=new JLabel("图书编号");
bookId.setFont(new Font