Java Swing + MySQL图书借阅管理系统

系列文章目录

Java Swing + MySQL 图书管理系统
Java Swing + MySQL 图书借阅管理系统


文章目录

  • 系列文章目录
  • 前言
  • 一、项目展示
  • 二、部分代码
    • 1.Book
    • 2.BookDao
    • 3.DBUtil
    • 4.BookAddInternalFrame
    • 5.Login
  • 三、配置


前言

项目是使用Java swing开发,界面设计比较简洁、适合作为Java课设设计以及学习技术使用。

  • 语言:Java
  • 界面:JavaSwing
  • 数据库:MySQL 8.x

具体功能如下:
1、基础功能
(1)系统登录功能:用户可以通过用户名和密码登录系统。
(2)图书分类管理功能:管理员可以对于图书的类别进行增、删、改、查操作。
(3)图书信息管理功能:能够增、删图书,修改图书名称、类别、价格等信息。
(4)图书借阅管理功能:包括图书借出和图书归还等操作,设计功能时需要考虑逾期情况的判别和处理。
2、可选加分功能
(1)借阅记录查询功能:学生可以查看自己在某时间段之内的借阅记录;管理员可以按照学号查询学生的借阅记录。(ps:只有管理员能够增删改查图书内容,用户只有查找书的信息的权限)

一、项目展示

image-20240527010008617

image-20240527010154137

image

image-20240527010339195

image-20240527010419245

image-20240527010455653

image-20240527010518137

image-20240527010632545

image-20240527010649613
image-20240527011013968

二、部分代码

1.Book

代码如下(示例):

package entity;

/**
 * BookManagementSystem
 * 图书
 *
 * @author PlutoCtx
 * @version 2024/5/26 1:07
 * @email ctx195467@163.com
 * @since JDK17
 */

public class Book {

    /**
     * 图书id
     */
    private int id;
    /**
     * 书名
     */
    private String bookName;
    /**
     * 作者
     */
    private String author;
    /**
     * 图书数量
     */
    private int number;
    /**
     * 价格
     */
    private Float price;
    /**
     * 图书类别
     */
    private Integer bookTypeId;
    /**
     * 图书类别
     */
    private String bookTypeName;
    /**
     * 描述
     */
    private String bookDesc;

    public Book(String bookName, String author, Integer number, Float price, Integer bookTypeId, String bookDesc) {
        super();
        this.bookName = bookName;
        this.author = author;
        this.number = number;
        this.price = price;
        this.bookTypeId = bookTypeId;
        this.bookDesc = bookDesc;
    }

    public Book(int id, String bookName, String author, Integer number, Float price, Integer bookTypeId, String bookDesc) {
        super();
        this.id = id;
        this.bookName = bookName;
        this.author = author;
        this.number = number;
        this.price = price;
        this.bookTypeId = bookTypeId;
        this.bookDesc = bookDesc;
    }

    public Book(String bookName, String author, Integer bookTypeId) {
        super();
        this.bookName = bookName;
        this.author = author;
        this.bookTypeId = bookTypeId;
    }


    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getBookName() {
        return bookName;
    }

    public void setBookName(String bookName) {
        this.bookName = bookName;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public int getNumber() {
        return number;
    }

    public void setNumber(int number) {
        this.number = number;
    }

    public Float getPrice() {
        return price;
    }

    public void setPrice(Float price) {
        this.price = price;
    }

    public Integer getBookTypeId() {
        return bookTypeId;
    }

    public void setBookTypeId(Integer bookTypeId) {
        this.bookTypeId = bookTypeId;
    }

    public String getBookTypeName() {
        return bookTypeName;
    }

    public void setBookTypeName(String bookTypeName) {
        this.bookTypeName = bookTypeName;
    }

    public String getBookDesc() {
        return bookDesc;
    }

    public void setBookDesc(String bookDesc) {
        this.bookDesc = bookDesc;
    }

    public Book() {
    }

    public Book(int id,
                String bookName,
                String author,
                Integer number,
                Float price,
                Integer bookTypeId,
                String bookTypeName,
                String bookDesc) {
        this.id = id;
        this.bookName = bookName;
        this.author = author;
        this.number = number;
        this.price = price;
        this.bookTypeId = bookTypeId;
        this.bookTypeName = bookTypeName;
        this.bookDesc = bookDesc;
    }


}

2.BookDao

代码如下(示例):

package dao;

import entity.Book;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * BookManagementSystem
 *
 * @author PlutoCtx
 * @version 2024/5/26 9:27
 * @email ctx195467@163.com
 * @since JDK17
 */

public class BookDao {


    /**
     * 添加图书
     * @param connection    连接数据库
     * @param book  书籍
     * @return  preparedStatement.executeUpdate(),int
     * @throws Exception    how do I know
     */
    public int add(Connection connection, Book book)throws Exception{
        String sql = "INSERT INTO book VALUES (null, ?, ?, ?, ?, ?, ?)";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1, book.getBookName());
        preparedStatement.setString(2, book.getAuthor());
        preparedStatement.setInt(3, book.getNumber());
        preparedStatement.setFloat(4, book.getPrice());
        preparedStatement.setInt(5, book.getBookTypeId());
        preparedStatement.setString(6, book.getBookDesc());
        return preparedStatement.executeUpdate();
    }

    /**
     * 查找书籍
     * @param connection    连接数据库
     * @param book  书籍
     * @return  preparedStatement.executeUpdate(), int
     * @throws Exception    how do I know
     */
    public ResultSet list(Connection connection, Book book)throws Exception{
        StringBuilder stringBuffer = new StringBuilder("SELECT * FROM book b,bookType bt WHERE b.bookTypeId = bt.id");
        if(book.getBookName() != null &&
                !book.getBookName().equals("")){
            stringBuffer.append(" and b.bookName like '%").append(book.getBookName()).append("%'");
        }

        if(book.getAuthor() != null &&
                !book.getAuthor().equals("")){
            stringBuffer.append(" and b.author like '%").append(book.getAuthor()).append("%'");
        }

        if(book.getBookTypeId() != null && book.getBookTypeId()!=-1){
            stringBuffer.append(" and b.bookTypeId=").append(book.getBookTypeId());
        }

        PreparedStatement preparedStatement = connection.prepareStatement(stringBuffer.toString());
        return preparedStatement.executeQuery();
    }


    /**
     * 删除书籍
     * @param connection    连接数据库
     * @param id 书籍id号
     * @return  preparedStatement.executeUpdate(), int
     * @throws Exception    how do I know
     */
    public int delete(Connection connection,String id)throws Exception{
        String sql = "DELETE FROM book " +
                "WHERE id = ?";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1, id);
        return preparedStatement.executeUpdate();
    }

    /**
     * 更新书籍
     * @param connection    连接数据库
     * @param book  书籍
     * @return  preparedStatement.executeUpdate(),int
     * @throws Exception    how do I know
     */
    public int update(Connection connection,Book book) throws Exception{
        String sql = "UPDATE book " +
                "SET bookName = ?, author = ?, number = ?, price = ?, bookDesc = ?, bookTypeId = ? " +
                "WHERE id = ?";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1, book.getBookName());
        preparedStatement.setString(2, book.getAuthor());
        preparedStatement.setInt(3, book.getNumber());
        preparedStatement.setFloat(4, book.getPrice());
        preparedStatement.setString(5, book.getBookDesc());
        preparedStatement.setInt(6, book.getBookTypeId());
        preparedStatement.setInt(7, book.getId());
        return preparedStatement.executeUpdate();
    }


    /**
     * 判断书籍是否存在
     * @param connection    数据库连接
     * @param bookTypeId    书类号
     * @return  存在与否
     * @throws Exception    异常多了什么都有可能
     */
    public boolean existBookByBookTypeId(Connection connection,String bookTypeId)throws Exception{
        String sql = "SELECT * FROM book WHERE bookTypeId = ?";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1, bookTypeId);
        ResultSet rs = preparedStatement.executeQuery();
        return rs.next();
    }

}

3.DBUtil

package utils;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 * BookManagementSystem
 * 数据库连接
 *
 * @author PlutoCtx
 * @version 2024/5/26 8:06
 * @email ctx195467@163.com
 * @since JDK17
 */

public class DBUtil {


    /**
     数据库
     */
    private String url = "jdbc:mysql://localhost:3306/BookBorrowingManagementSystem";
    /**
     * 用户名
     */
    private String username = "root";
    /**
     * 密码
     */
    private String password = "Shangxiao111";
    /**
     * 驱动名称
     */
    private String jdbcName = "com.mysql.cj.jdbc.Driver";

    /**
     * 获取数据库连接
     * @return  返回连接
     * @throws Exception 没连上
     */
    public Connection getConnection() throws Exception{
        Class.forName(jdbcName);
        Connection connection = DriverManager.getConnection(url, username, password);
        return connection;
    }


    /**
     * 关闭数据库连接
     * @param connection    数据库连接
     * @throws Exception    异常
     */
    public void closeConnection(Connection connection) throws Exception{
        if (connection != null){
            connection.close();
        }
    }

}

4.BookAddInternalFrame

package view.adminOperation;

import dao.BookDao;
import dao.BookTypeDao;
import entity.Book;
import entity.BookType;
import utils.DBUtil;

import javax.swing.*;
import javax.swing.border.LineBorder;
import java.awt.event.ActionEvent;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.Objects;
import java.util.logging.Logger;

/**
 * BookManagementSystem
 * 图书添加界面
 *
 * @author PlutoCtx
 * @version 2024/5/26 9:08
 * @email ctx195467@163.com
 * @since JDK17
 */

public class BookAddInternalFrame extends JInternalFrame {
    private final JTextField bookNameTxt;
    private final JTextField authorTxt;
    private final JTextField bookNumberTxt;

    private final ButtonGroup buttonGroup = new ButtonGroup();
    private final JTextField priceTxt;
    private final JComboBox bookTypeJcb;
    private final JTextArea bookDescTxt;

    private final DBUtil dbUtil = new DBUtil();
    private final BookTypeDao bookTypeDao = new BookTypeDao();
    private final BookDao bookDao = new BookDao();


    /**
     * Create the frame.
     */
    public BookAddInternalFrame() {
        setClosable(true);
        setIconifiable(true);
        setTitle("图书添加");
        setBounds(100, 100, 450, 467);

        JLabel label = new JLabel("图书名称:");
        bookNameTxt = new JTextField();
        bookNameTxt.setColumns(10);


        JLabel label1 = new JLabel("图书作者:");
        authorTxt = new JTextField();
        authorTxt.setColumns(10);



        JLabel label2 = new JLabel("图书数量:");
        bookNumberTxt = new JTextField();
        bookNumberTxt.setColumns(10);

        JLabel label3 = new JLabel("图书价格:");

        priceTxt = new JTextField();
        priceTxt.setColumns(10);

        JLabel label4 = new JLabel("图书描述:");

        bookDescTxt = new JTextArea();

        JLabel label5 = new JLabel("图书类别:");

        bookTypeJcb = new JComboBox();

        JButton button = new JButton("添加");
        button.addActionListener(this::bookAddActionPerformed);
        button.setIcon(new ImageIcon(Objects.requireNonNull(BookAddInternalFrame.class.getResource("/add.png"))));

        JButton button1 = new JButton("重置");
        button1.addActionListener(this::resetValueActionPerformed);
        button1.setIcon(new ImageIcon(Objects.requireNonNull(BookAddInternalFrame.class.getResource("/reset.png"))));
        GroupLayout groupLayout = new GroupLayout(getContentPane());
        groupLayout.setHorizontalGroup(
                groupLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                        .addGroup(groupLayout.createSequentialGroup()
                                .addGap(42)
                                .addGroup(groupLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                        .addGroup(groupLayout.createSequentialGroup()
                                                .addComponent(button)
                                                .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(button1)
                                                .addGap(232))
                                        .addGroup(groupLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                                .addComponent(label5)
                                                .addGroup(groupLayout.createSequentialGroup()
                                                        .addGroup(groupLayout.createParallelGroup(GroupLayout.Alignment.TRAILING)
                                                                .addComponent(label4)
                                                                .addComponent(label2)
                                                                .addComponent(label))
                                                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                                        .addGroup(groupLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                                                .addGroup(groupLayout.createSequentialGroup()
                                                                        .addGroup(groupLayout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
                                                                                .addComponent(bookNameTxt, GroupLayout.PREFERRED_SIZE, 88, GroupLayout.PREFERRED_SIZE)
                                                                                .addComponent(bookNumberTxt, GroupLayout.PREFERRED_SIZE, 88, GroupLayout.PREFERRED_SIZE)
                                                                                .addComponent(bookTypeJcb, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                                                        .addGap(35)
                                                                        .addGroup(groupLayout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
                                                                                .addGroup(groupLayout.createSequentialGroup()
                                                                                        .addComponent(label1)
                                                                                        .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                                                                        .addComponent(authorTxt, GroupLayout.PREFERRED_SIZE, 91, GroupLayout.PREFERRED_SIZE))
                                                                                .addGroup(groupLayout.createSequentialGroup()
                                                                                        .addComponent(label3)
                                                                                        .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                                                                        .addComponent(priceTxt))))
                                                                .addComponent(bookDescTxt))
                                                        .addContainerGap(44, Short.MAX_VALUE)))))
        );
        groupLayout.setVerticalGroup(
                groupLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                        .addGroup(groupLayout.createSequentialGroup()
                                .addGap(42)
                                .addGroup(groupLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                        .addComponent(label)
                                        .addComponent(bookNameTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                                        .addComponent(label1)
                                        .addComponent(authorTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                                .addGap(29)
                                .addGroup(groupLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                        .addComponent(label2)
                                        .addComponent(bookNumberTxt)
                                        .addComponent(label3)
                                        .addComponent(priceTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                                .addGap(33)
                                .addGroup(groupLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                        .addComponent(label5)
                                        .addComponent(bookTypeJcb, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                                .addGap(30)
                                .addGroup(groupLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                        .addComponent(label4)
                                        .addComponent(bookDescTxt, GroupLayout.PREFERRED_SIZE, 137, GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 37, Short.MAX_VALUE)
                                .addGroup(groupLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                        .addComponent(button)
                                        .addComponent(button1))
                                .addGap(42))
        );
        getContentPane().setLayout(groupLayout);

        /*
         * 设置文本域边框
         */
        bookDescTxt.setBorder(new LineBorder(new java.awt.Color(127,157,185), 1, false));
        fillBookType();
    }





    /**
     * 重置事件处理
     * @param e event
     */
    private void resetValueActionPerformed(ActionEvent e) {
        this.resetValue();
    }


    /**
     * 图书添加事件处理
     * @param event event
     */
    private void bookAddActionPerformed(ActionEvent event) {
        String bookName = this.bookNameTxt.getText();
        String author = this.authorTxt.getText();
        String price = this.priceTxt.getText();
        String bookDesc = this.bookDescTxt.getText();

        if(bookName == null || "".equals(bookName.trim())){
            JOptionPane.showMessageDialog(null, "图书名称不能为空");
            return;
        }

        if(author == null || "".equals(author.trim())){
            JOptionPane.showMessageDialog(null, "图书作者不能为空");
            return;
        }

        if(price == null || "".equals(price.trim())){
            JOptionPane.showMessageDialog(null, "图书价格不能为空");
            return;
        }

        String bookNumber = bookNumberTxt.getText();
        int numberOfBook = bookNumber.isEmpty() ? 0 : Integer.parseInt(bookNumber);


        BookType bookType = (BookType) bookTypeJcb.getSelectedItem();
        int bookTypeId = bookType.getId();

        Book book = new Book(bookName,author, numberOfBook, Float.parseFloat(price) , bookTypeId,  bookDesc);

        Connection con = null;
        try{
            con = dbUtil.getConnection();
            int addNum = bookDao.add(con, book);
            if(addNum == 1){
                JOptionPane.showMessageDialog(null, "图书添加成功");
                resetValue();
            }else{
                JOptionPane.showMessageDialog(null, "图书添加失败");
            }
        }catch(Exception e){
            e.printStackTrace();
            JOptionPane.showMessageDialog(null, "图书添加失败");
        }finally{
            try {
                dbUtil.closeConnection(con);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }




    /**
     * 重置表单
     */
    private void resetValue(){
        this.bookNameTxt.setText("");
        this.authorTxt.setText("");
        this.priceTxt.setText("");
        this.bookNumberTxt.setText("");
        this.bookDescTxt.setText("");
        if(this.bookTypeJcb.getItemCount()>0){
            this.bookTypeJcb.setSelectedIndex(0);
        }
    }


    /**
     * 初始化图书类别下拉框
     */
    private void fillBookType(){
        Connection con = null;
        BookType bookType = null;
        try{
            con = dbUtil.getConnection();
            ResultSet rs = bookTypeDao.list(con, new BookType());
            while(rs.next()){
                bookType = new BookType();
                bookType.setId(rs.getInt("id"));
                bookType.setBookTypeName(rs.getString("bookTypeName"));
                this.bookTypeJcb.addItem(bookType);
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally{
            Logger.getGlobal().info("finished!");
        }
    }
}

5.Login

package view;

import dao.UserDao;
import entity.User;
import utils.DBUtil;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.plaf.FontUIResource;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.sql.Connection;
import java.util.Enumeration;
import java.util.Objects;

/**
 * BookManagementSystem
 * 登录界面
 *
 * @author PlutoCtx
 * @version 2024/5/26 8:17
 * @email ctx195467@163.com
 * @since JDK17
 */

public class Login extends JFrame {

    private JPanel contentPane;
    private final JTextField userNameText;
    private final JPasswordField passwordText;

    private final DBUtil dbUtil = new DBUtil();
    private final UserDao userDao = new UserDao();

    /**
     * Create the frame
     */
    public Login(){
        //改变系统默认字体
        Font font = new Font("Dialog", Font.PLAIN, 12);
        Enumeration<Object> keys = UIManager.getDefaults().keys();
        while (keys.hasMoreElements()){
            Object key = keys.nextElement();
            Object value = UIManager.get(key);
            if (value instanceof FontUIResource){
                UIManager.put(key, font);
            }
        }
        setResizable(false);
        // 用户登录
        setTitle("用户登录");
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setBounds(500,250,450,343);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5,5,5,5));
        setContentPane(contentPane);

        JLabel lblNewLabel = new JLabel("图书管理系统");
        lblNewLabel.setFont(new Font("宋体", Font.BOLD, 23));
        lblNewLabel.setIcon(new ImageIcon(Objects.requireNonNull(getClass().getResource("/logo.png"))));

        JLabel lblNewLabel1 = new JLabel("用户名:");
        lblNewLabel1.setIcon(new ImageIcon(Objects.requireNonNull(getClass().getResource("/userName.png"))));


        JLabel lblNewLabel2 = new JLabel("密  码:");
        lblNewLabel2.setIcon(new ImageIcon(Objects.requireNonNull(getClass().getResource("/password.png"))));

        userNameText = new JTextField();
        userNameText.setColumns(10);

        passwordText = new JPasswordField();

        JButton btnNewButton1 = new JButton("登录");
        btnNewButton1.addActionListener(this::loginActionPerformed);
        btnNewButton1.setIcon(new ImageIcon(Objects.requireNonNull(getClass().getResource("/login.png"))));

        JButton btnNewButton2 = new JButton("重置");
        btnNewButton2.addActionListener(this::resetValueActionPerformed);
        btnNewButton2.setIcon(new ImageIcon(Objects.requireNonNull(getClass().getResource("/reset.png"))));


        GroupLayout groupLayoutContentPane = new GroupLayout(contentPane);
        groupLayoutContentPane.setHorizontalGroup(
                groupLayoutContentPane.createParallelGroup(GroupLayout.Alignment.LEADING)
                        .addGroup(groupLayoutContentPane.createSequentialGroup()
                                .addGroup(groupLayoutContentPane.createParallelGroup(GroupLayout.Alignment.LEADING)
                                        .addGroup(groupLayoutContentPane.createSequentialGroup()
                                                .addGap(111)
                                                .addComponent(lblNewLabel))
                                        .addGroup(groupLayoutContentPane.createSequentialGroup()
                                                .addGap(101)
                                                .addGroup(groupLayoutContentPane.createParallelGroup(GroupLayout.Alignment.LEADING)
                                                        .addComponent(lblNewLabel1)
                                                        .addComponent(lblNewLabel2)
                                                        .addComponent(btnNewButton1))
                                                .addGap(32)
                                                .addGroup(groupLayoutContentPane.createParallelGroup(GroupLayout.Alignment.LEADING)
                                                        .addComponent(btnNewButton2)
                                                        .addGroup(groupLayoutContentPane.createParallelGroup(GroupLayout.Alignment.LEADING, false)
                                                                .addComponent(passwordText)
                                                                .addComponent(userNameText, GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE)))))
                                .addContainerGap(111, Short.MAX_VALUE))
        );
        groupLayoutContentPane.setVerticalGroup(
                groupLayoutContentPane.createParallelGroup(GroupLayout.Alignment.LEADING)
                        .addGroup(groupLayoutContentPane.createSequentialGroup()
                                .addGap(30)
                                .addComponent(lblNewLabel)
                                .addGap(26)
                                .addGroup(groupLayoutContentPane.createParallelGroup(GroupLayout.Alignment.LEADING)
                                        .addGroup(groupLayoutContentPane.createSequentialGroup()
                                                .addComponent(lblNewLabel1)
                                                .addGap(29)
                                                .addGroup(groupLayoutContentPane.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                                        .addComponent(lblNewLabel2)
                                                        .addComponent(passwordText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
                                        .addComponent(userNameText, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                                .addGap(36)
                                .addGroup(groupLayoutContentPane.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                        .addComponent(btnNewButton1)
                                        .addComponent(btnNewButton2))
                                .addContainerGap(60, Short.MAX_VALUE))
        );
        contentPane.setLayout(groupLayoutContentPane);
        // 居中
        this.setLocationRelativeTo(null);
    }

    /**
     * 登录事件处理
     * @param evt action
     */
    private void loginActionPerformed(ActionEvent evt) {
        String userName = this.userNameText.getText();
        String password = new String(this.passwordText.getPassword());
        if (userName == null || userName.equals("")){
            JOptionPane.showMessageDialog(null, "用户名不能为空");
            return;
        }
        if (password == null || password.equals("")){
            JOptionPane.showMessageDialog(null, "密码不能为空");
            return;
        }

        // 调用dao层方法
        User user = new User(userName, password);
        Connection con = null;
        try {
            con = dbUtil.getConnection();
            User currentUser = userDao.login(con, user);
            if (currentUser != null){
                dispose();
                if (currentUser.getStatus() == 1) {
                    new AdminMainFrame(currentUser).setVisible(true);
                    JOptionPane.showMessageDialog(null, "登录成功");
                } else {
                    new UserMainFrame(currentUser).setVisible(true);
                    JOptionPane.showMessageDialog(null, "登录成功");
                }
            }else {
                JOptionPane.showMessageDialog(null, "用户名或密码错误");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                dbUtil.closeConnection(con);
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }

    /**
     * 重置事件处理
     * @param evt action
     */
    private void resetValueActionPerformed(ActionEvent evt){
        this.userNameText.setText("");
        this.passwordText.setText("");
    }

}



三、配置

1、idea直接导入解压文件夹
2、打开navicat等数据库可视化软件,运行sql文件夹下的数据库文件
3、修改DBUtil.java中的用户名、连接、密码(如果有必要的话)
4、运行Main

如有购买需求,请移步到 面包多 进行购买,CSDN的收费太黑了

面包多中提供了几种不同的版本代码:

  • JavaSwing+MySQL图书管理系统 有数据库版,提供MySQL支持,数据能够实现增删改查
  • JavaSwing+MySQL图书管理系统 无数据库版,仅提供界面和部分鼠标点击事件,数据内容无法被修改
  • JavaSwing+MySQL图书借阅管理系统 有数据库版,提供MySQL支持,数据能够实现增删改查

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/647914.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

冯喜运:5.27黄金暴跌大阴后出现“暂定符”今日黄金原油操作策略

【黄金消息面分析】&#xff1a;金价虽然有大阴线暴跌&#xff0c;但依然属于超买后的调整而非熊市&#xff0c;对中长线投资者来说只是市场洗牌。因此&#xff0c;在出现企稳迹象之后&#xff0c;随时关注反弹时机的启动。未来几日&#xff0c;黄金空头可能在进一步发力之前需…

【机器学习结合AI绘画工具】——开启艺术创作的新纪元

目录 一、AI绘画工具的发展历程 二、AI绘画工具的技术原理 实例说明 三、AI绘画工具在艺术创作中的应用 实例网站 四、AI绘画工具的影响与未来展望 结论 机器学习和人工智能&#xff08;AI&#xff09;在过去的十年里取得了显著的进展。特别是在艺术创作领域&#xff0c…

Qt 对话框或者QMainWindow等类中调用自定义QWidget继承组件

简单的方法如下所示 1、创建一个ui文件&#xff0c;界面布局放入QVBoxLayout或者QHBoxLayout 使用他来放入自定义组件&#xff0c;类似如下 2、代码如下&#xff1a; ui.setupUi(this); { //自定义组价如下 KwTable *Table new KwTable(this); ui.vertical…

Java中的类加载器

类加载器 1.什么是类加载器&#xff1f; 启动类加载器&#xff08;Bootstrap ClassLoader&#xff09;&#xff1a;这是JVM自带的类加载器&#xff0c;负责加载Java的核心类库&#xff0c;如rt.jar等。由于安全原因&#xff0c;启动类加载器加载的类不能被其他类加载器加载的类…

python 两个表格字段列名称值,对比字段差异

支持xlsx,xls文件&#xff0c;相互对比字段列 输出两个表格文件相同字段&#xff0c;置底色为绿色 存在差异的不同字段&#xff0c;输出两个新的表格文件&#xff0c;差异字段&#xff0c;置底色为红色 import pandas as pd from openpyxl import load_workbook from openpy…

【云原生】Kubernetes-----POD资源限制与探针机制

目录 引言 一、资源限制 &#xff08;一&#xff09;基本定义 &#xff08;二&#xff09;资源单位 1.CPU资源 2.内存资源 &#xff08;三&#xff09;请求与限制 &#xff08;四&#xff09;定义方式 1.编写yaml文件 2.查看资源情况 &#xff08;五&#xff09;资源…

Gradient-checkpointing的原理

原文&#xff1a; 将更大的网络安装到内存中。|by 雅罗斯拉夫布拉托夫 |张量流 |中等 (medium.com) 前向传播时&#xff0c;隔几层就保留一层activation数据&#xff0c;其余层的activation都释放掉&#xff1b; 反向传播时&#xff0c;从最近的checkpoint去重新跑forward&…

Cohere继Command-R+之后发布大模型Aya-23,性能超越 Gemma、Mistral 等,支持中文

前言 近年来&#xff0c;多语言大模型&#xff08;MLLM&#xff09;发展迅速&#xff0c;但大多数模型的性能依然存在显著差距&#xff0c;尤其是在非英语语言方面表现不佳。为了推动多语言自然语言处理技术的发展&#xff0c;Cohere团队发布了新的多语言指令微调模型家族——…

cpolar内网穿透工具—无需部署,远程访问网址

文章目录 cpolar介绍安装教程隧道管理VIP客户cpolar介绍 cpolar是一种安全的内网穿透服务,它将局域网下面的本地服务器通过加密隧道暴露至公网,使得公网用户可以正常访问内网服务。 只需一行命令,就可以将内网站点发布至公网,方便给客户演示。高效调试微信公众号、小程序…

设计模式:适配器模式(Adapter)

设计模式&#xff1a;适配器模式&#xff08;Adapter&#xff09; 设计模式&#xff1a;适配器模式&#xff08;Adapter&#xff09;模式动机模式定义模式结构时序图模式实现在单线程环境下的测试在多线程环境下的测试模式分析优缺点适用场景应用场景应用实例适配器模式和代理模…

JAVA实现图书管理系统(初阶)

一.抽象出对象: 1.要有书架&#xff0c;图书&#xff0c;用户&#xff08;包括普通用户&#xff0c;管理员用户&#xff09;。根据这些我们可以建立几个包&#xff0c;来把繁杂的代码分开&#xff0c;再通过一个类来把这些&#xff0c;对象整合起来实现系统。说到整合&#xf…

Day04:CSS 进阶

目标&#xff1a;掌握复合选择器作用和写法&#xff1b;使用background属性添加背景效果 一、复合选择器 定义&#xff1a;由两个或多个基础选择器&#xff0c;通过不同的方式组合而成。 作用&#xff1a;更准确、更高效的选择目标元素&#xff08;标签&#xff09;。 1、后…

ros 学习记录(四)仿真环境中键盘控制turtlebot3运动

仿真环境中键盘控制turtlebot3运动 准备工作1. 监听键盘敲击&#xff1a;key_publisher.py2. 控制turtlebot3运动&#xff1a;keys_to_twist_using_rate.py3. 测试4. 数据监视 准备工作 名称版本ROSNoeticGazebo11.11.0python3.8.10 turtlebot3的安装与仿真环境搭建请看上一篇…

视频播放器-Kodi

一、前言 Kodi 是一款开源免费的多媒体播放软件。Kodi 是由非营利性技术联盟 Kodi 基金会开发的免费开源媒体播放器应用程序。 Kodi是一款免费和开源&#xff08;遵循GPL协议&#xff09;的多媒体播放器和娱乐中心软件&#xff0c;由XBMC基金会开发。Kodi的主要功能是管理和播…

three.js判断物体在人的前面,还是后面

three.js判断物体在人的前面&#xff0c;还是后面 const player new THREE.Vectors(10, 0, 5); const mesh new THREE.Vectors(15, 0, 6);上面&#xff0c;两个变量分别表示&#xff0c;玩家的位置&#xff0c;物体的位置。 从这发现&#xff0c;当玩家和物体的角度关系 小…

报错:c2665 ”loadimage“没有重载函数可以转换所有参数类型

解决方法: 右键项目选择属性-》高级-》字符集-》使用多字节字符集-》确定

SparkStreaming概述

Spark概述 SparkStreaming概述 Spark Streaming 是 Apache Spark 生态系统中的一个组件&#xff0c;用于实时流数据处理。它允许用户通过流式计算引擎处理实时数据流&#xff0c;并以低延迟的方式对数据进行分析、处理和存储。 背景 在大数据领域&#xff0c;传统的批处理系统…

什么是云渗透测试?

推荐阅读&#xff1a; 什么是安全态势&#xff1f; 什么是人肉搜索 什么是恶意软件&#xff1f; 什么是数字取证&#xff1f; 什么是语音网络钓鱼&#xff1f; 什么是网络安全中的社会工程&#xff1f; 什么是网络安全中的威胁情报&#xff1f; 什么是端点检测和响应 (…

Java进阶:详解与实战Java Stream API

Java进阶&#xff1a;详解与实战Java Stream API &#x1f31f; Java进阶&#xff1a;详解与实战Java Stream API &#x1f31f;摘要引言一、Java Stream API介绍&#x1f4da;1. 什么是Java Stream API&#xff1f;2. Java Stream API支持的功能3. 使用Java Stream API的优势…

【vue3+elementuiplus】el-select下拉框会自动触发校验规则

场景&#xff1a;编辑弹框省份字段下拉框必填&#xff0c;触发方式change&#xff0c;有值第一次打开不会触发校验提示&#xff0c;关闭弹框再次打开触发必填校验提示&#xff0c;但是该字段有值 问题的原因是&#xff1a;在关闭弹层事件中&#xff0c;我做了resetfileds&…