基于java的Swing+MySQL图书借阅管理系统图书管理系统(java+swing+mysql)

运行环境

Java≥8、MySQL≥5.7

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

072323230409

082323230409

092323230409

102323230409

112323230409

122323230409

132323230409

基于java的Swing+MySQL图书借阅管理系统图书管理系统(java+swing+mysql)

启动类:
LoginFrm

管理员:
admin 123456

用户:
user1 123456
user2 123456
user3 123456

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
		int x = random.nextInt(width - 1);
int y = random.nextInt(height - 1);
int x1 = random.nextInt(width - 10) + 10;
int y1 = random.nextInt(height - 4) + 4;
g2d.setColor(getRandColor(180, 200));
g2d.drawLine(x, y, x1, y1);
}

/*i = 0; len = 300;
for (; i < len; i++) {
int x = random.nextInt(width);
int y = random.nextInt(height);
g2d.setColor(getRandColor(150, 180));
g2d.drawRect(x, y, 0, 0);
}*/

//绘制出验证码的具体字母
i = 0; len = this.codeLength;
FontMetrics fm = g2d.getFontMetrics();
int base = (height - fm.getHeight())/2 + fm.getAscent();
for(;i<len;i++) {
int b = random.nextBoolean() ? 1 : -1;
g2d.rotate(random.nextInt(10)*0.01*b);
g2d.setColor(getRandColor(20, 130));
g2d.drawString(code.charAt(i)+"", 16 * i + 10, base);
}
}

//下一个验证码
public void nextCode() {
generateCode();
repaint();
}

@Override
public void mouseClicked(MouseEvent e) {

nextCode();
}

@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub

}

@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub

}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
	if (min > 255)
min = 255;
if (max > 255)
max = 255;
int red = random.nextInt(max - min) + min;
int green = random.nextInt(max - min) + min;
int blue = random.nextInt(max - min) + min;
return new Color(red, green, blue);
}
/*
设置验证码具体的字母是什么
*/
protected String generateCode() {
char[] codes = new char[this.codeLength];
for (int i = 0, len = codes.length; i < len; i++) {
if (random.nextBoolean()) {
codes[i] = (char) (random.nextInt(26) + 65);
} else {
codes[i] = (char) (random.nextInt(26) + 97);
}
}
this.code = new String(codes);
return this.code;
}

@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
if(this.code == null || this.code.length() != this.codeLength) {
this.code = generateCode();
}
width = this.codeLength * 16 + (this.codeLength - 1) * 10;
super.setSize(width, height);
super.setPreferredSize(new Dimension(width, height));
Font mFont = new Font("Arial", Font.BOLD | Font.ITALIC, 25);
g.setFont(mFont);
//绘制出验证码的背景的矩形轮廓
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(getRandColor(200, 250));
g2d.fillRect(0, 0, width, height);
g2d.setColor(getRandColor(180, 200));
g2d.drawRect(0, 0, width - 1, height - 1);
//绘制出验证码背景的线
int i = 0, len = 150;
for (; i < len; i++) {
int x = random.nextInt(width - 1);
int y = random.nextInt(height - 1);
int x1 = random.nextInt(width - 10) + 10;
int y1 = random.nextInt(height - 4) + 4;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
mnNewMenu.add(mntmNewMenuItem_1);

JMenu mnNewMenu_2 = new JMenu("书籍管理");
menuBar.add(mnNewMenu_2);

JMenuItem mntmNewMenuItem_2 = new JMenuItem("书籍添加");
mnNewMenu_2.add(mntmNewMenuItem_2);

JMenuItem mntmNewMenuItem_3 = new JMenuItem("书籍修改");
mntmNewMenuItem_3.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent evt) {
jf.dispose();
new AdminBookEdit();
}
});
mnNewMenu_2.add(mntmNewMenuItem_3);

JMenu menu1 = new JMenu("用户管理");
menuBar.add(menu1);

JMenuItem mntmNewMenuItem_4 = new JMenuItem("用户信息");
mntmNewMenuItem_4.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent evt) {
jf.dispose();
new AdminUserInfo();
}
});
menu1.add(mntmNewMenuItem_4);

JMenuItem mntmNewMenuItem_5 = new JMenuItem("借阅信息");
mntmNewMenuItem_5.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent evt) {
jf.dispose();
new AdminBorrowInfo();
}
});
menu1.add(mntmNewMenuItem_5);

JMenu mnNewMenu_1 = new JMenu("退出系统");
mnNewMenu_1.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent evt) {
JOptionPane.showMessageDialog(null, "欢迎再次使用");
jf.dispose();
}
});
menuBar.add(mnNewMenu_1);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
lblNewLabel_1 = new JLabel("New label");
lblNewLabel_1.setForeground(Color.RED);
lblNewLabel_1.setFont(new Font("Dialog", Font.BOLD, 18));
lblNewLabel_1.setBounds(315, 10, 197, 28);
jf.getContentPane().add(lblNewLabel_1);
lblNewLabel_1.setText(LoginFrm.currentUser.getUserName());

lblNewLabel_2 = new JLabel("欢迎您,");
lblNewLabel_2.setFont(new Font("Dialog", Font.BOLD, 18));
lblNewLabel_2.setBounds(254, 11, 258, 28);
jf.getContentPane().add(lblNewLabel_2);

JPanel panel = new JPanel();
panel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "\u8FD8\u4E66", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(255, 0, 0)));
panel.setBounds(23, 294, 651, 70);
jf.getContentPane().add(panel);
panel.setLayout(null);

JLabel lblNewLabel = new JLabel("编号:");
lblNewLabel.setBounds(90, 25, 51, 27);
panel.add(lblNewLabel);
lblNewLabel.setFont(new Font("幼圆", Font.BOLD, 16));

textField = new JTextField();
textField.setBounds(145, 28, 116, 24);
panel.add(textField);
textField.setColumns(10);

btnBackBook = new JButton("还书");
btnBackBook.setFont(new Font("Dialog", Font.BOLD, 15));
btnBackBook.setBounds(299, 25, 85, 31);
panel.add(btnBackBook);

button = new JButton("退出系统");
button.setFont(new Font("Dialog", Font.BOLD, 15));
button.setBounds(407, 25, 103, 31);
panel.add(button);

panel_2 = new JPanel();
panel_2.setBorder(new TitledBorder(null, "借阅信息", TitledBorder.LEADING, TitledBorder.TOP, null, Color.RED));
panel_2.setBounds(23, 374, 651, 346);
jf.getContentPane().add(panel_2);
panel_2.setLayout(null);

textField_1 = new JTextField();
textField_1.setColumns(10);
textField_1.setBounds(252, 23, 135, 27);
panel_2.add(textField_1);

button_1 = new JButton("查询");
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
	mnNewMenu_1.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent evt) {
JOptionPane.showMessageDialog(null, "欢迎再次使用");
jf.dispose();
}
});
menuBar.add(mnNewMenu_1);

JPanel panel_1 = new JPanel();
panel_1.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "借阅信息", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(255, 0, 0)));
panel_1.setBounds(10, 10, 574, 350);

/*做一个表头栏数据 一位数组
* */
String[] title={"借书人","书名","状态","借书时间","还书时间"};
/*具体的各栏行记录 先用空的二位数组占位*/
String[][] dates={};
/*然后实例化 上面2个控件对象*/
model=new DefaultTableModel(dates,title);
table=new JTable(model);
putDates(new BorrowDetail());//获取数据库数据放置table中
panel_1.setLayout(null);
JScrollPane jscrollpane = new JScrollPane();
jscrollpane.setBounds(20, 22, 538, 314);
jscrollpane.setViewportView(table);
panel_1.add(jscrollpane);
jf.getContentPane().add(panel_1);

JLabel lblNewLabel = new JLabel("");
lblNewLabel.setIcon(new ImageIcon(AdminBorrowInfo.class.getResource("/tupian/adBG2.png")));
lblNewLabel.setBounds(0, 0, 584, 379);
jf.getContentPane().add(lblNewLabel);

jf.setVisible(true);
jf.setResizable(true);
}
private void putDates(BorrowDetail borrowDetail) {
DefaultTableModel model = (DefaultTableModel) table.getModel();
model.setRowCount(0);
Connection con = null;
try {
con = dbUtil.getConnection();
ResultSet list = borrowDetailDao.list(con, borrowDetail);
while (list.next()) {
Vector rowData = new Vector();
rowData.add(list.getString("username"));
rowData.add(list.getString("book_name"));
int status = list.getInt("status");
if (status == 1) {
rowData.add("在借");


项目链接:
https://javayms.github.io?id=062323230409201ec
https://javayms.pages.dev?id=062323230409201ec