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

运行环境

Java≥8、MySQL≥5.7

开发工具

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

适用

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

功能说明

040123062402

050123062402

060123062402

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

功能介绍:借阅列表、图书类别管理、图书馆里、用户管理、借阅管理、关于我们

  

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
private JComboBox jcb_bookType;
private JTextArea bookDescTxt;

/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
BookAddInterFrm frame = new BookAddInterFrm();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

/**
* Create the frame.
*/
public BookAddInterFrm() {

setClosable(true);
setIconifiable(true);
setTitle("\u56FE\u4E66\u6DFB\u52A0");
setBounds(100, 100, 474, 443);
setLocation(500, 100);
getContentPane().setLayout(null);

init();
fillBookType();

}

private void init() {
JLabel lb_bookName = new JLabel("\u56FE\u4E66\u540D\u79F0\uFF1A");
lb_bookName.setBounds(29, 39, 72, 15);
getContentPane().add(lb_bookName);
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
		jb_return.setBounds(10, 68, 635, 23);
panel_1.add(jb_return);
}
}
package cn.edu.sau.view;




public class BookAddInterFrm extends JInternalFrame {
DbUtil dbUtil = new DbUtil();
BookTypeDao bookTypeDao = new BookTypeDao();
BookDao bookDao = new BookDao();

private JTextField bookNameTxt;
private JTextField bookAuthorTxt;
private JTextField bookPriceTxt;
private JComboBox jcb_bookType;
private JTextArea bookDescTxt;

/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
BookAddInterFrm frame = new BookAddInterFrm();
frame.setVisible(true);
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
			}
});
mnNewMenu_2.add(menuItem_1);
}
}
package cn.edu.sau.view;




public class LogonFrm extends JFrame {

private JPanel contentPane;
private JTextField userNameTxt;
private JPasswordField userPasswordTxt;

/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
LogonFrm frame = new LogonFrm();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
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
53
				e.printStackTrace();
}
}
});
}

/**
* Create the frame.
*/
public BookManageInterFrm() {
setClosable(true);
setIconifiable(true);
setTitle("\u56FE\u4E66\u7BA1\u7406");
setBounds(100, 100, 812, 618);
setLocation(300, 20);
getContentPane().setLayout(null);

init();

fillTable(new Book());
this.fillBookType("search");
this.fillBookType("modify");

}

// 填充下拉菜单
private void fillBookType(String type) {
Connection con = null;
BookType bookType = null;
try {
con = dbUtil.getCon();
ResultSet rs = bookTypeDao.bookTypeList(con, new BookType());
if ("search".equals(type)) {
bookType = new BookType();
bookType.setBookTypeName("请选择...");
bookType.setId(-1);
this.s_jcbBookType.addItem(bookType);
}
while (rs.next()) {
bookType = new BookType();
bookType.setId(rs.getInt("id"));
bookType.setBookTypeName(rs.getString("bookTypeName"));
if ("search".equals(type)) {
this.s_jcbBookType.addItem(bookType);
} else if ("modify".equals(type)) {
this.jcb_bookType.addItem(bookType);
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
dbUtil.closeCon(con);
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
			return;
}
if (StringUtil.isEmpty(userPassword)) {
JOptionPane.showMessageDialog(null, "密码不能为空");
return;
}
User user = new User(userName, userPassword);
Connection con = null;

try {
con = dbUtil.getCon();
User reUser = userDao.login(con, user);
if (reUser != null) {
dispose();// 销毁登录框
if (1 == reUser.getRole()) {
new MainFrm().setVisible(true);// 创建管理员主界面Firme
} else if (0 == reUser.getRole()) {
new UserMainFrm(reUser).setVisible(true); // 创建读者界面
}
} else {
JOptionPane.showMessageDialog(null, "用户名或密码不正确");
}
} catch (Exception e1) {
JOptionPane.showMessageDialog(null, "登录失败");
e1.printStackTrace();
} finally {
try {
con.close();
} catch (SQLException e1) {
e1.printStackTrace();
}
}

}
});
jb_login.setBounds(102, 191, 93, 23);
contentPane.add(jb_login);
// 重置按钮
JButton jb_reset = new JButton("\u91CD\u7F6E");
jb_reset.setIcon(new ImageIcon(
"D:\\java\\MyBookManager\\image\\reset.png"));
jb_reset.addActionListener(new ActionListener() {
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
			v.add(rs.getInt("id"));
v.add(rs.getString("bookName"));
v.add(rs.getString("author"));
v.add(rs.getFloat("price"));
v.add(rs.getString("bookDesc"));
v.add(rs.getString("bookTypeName"));
dtm.addRow(v);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
dbUtil.closeCon(con);
} catch (Exception e) {
e.printStackTrace();
}
}
}

private void init() {
scrollPane = new JScrollPane();
scrollPane.setToolTipText("");
scrollPane.setBounds(30, 91, 732, 178);
getContentPane().add(scrollPane);

bookTable = new JTable();
bookTable.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
int row = bookTable.getSelectedRow();
idTxt.setText((Integer) bookTable.getValueAt(row, 0) + "");
bookNameTxt.setText((String) bookTable.getValueAt(row, 1));
bookAuthorTxt.setText((String) bookTable.getValueAt(row, 2));
bookPriceTxt.setText((Float) bookTable.getValueAt(row, 3) + "");
bookDescTxt.setText(bookTable.getValueAt(row, 4) + "");
String bookTypeName = (String) bookTable.getValueAt(row, 5);
int n = jcb_bookType.getItemCount();
for (int i = 0; i < n; i++) {
BookType item = (BookType) jcb_bookType.getItemAt(i);
if (item.getBookTypeName().equals(bookTypeName)) {
jcb_bookType.setSelectedIndex(i);
}
}
}
});
bookTable.setToolTipText("\u56FE\u4E66");
bookTable.setSurrendersFocusOnKeystroke(true);
bookTable.setModel(new DefaultTableModel(new Object[][] { { null, null,
null, null, null, null }, }, new String[] {
"\u56FE\u4E66\u7F16\u53F7", "\u56FE\u4E66\u540D\u79F0",
"\u56FE\u4E66\u4F5C\u8005", "\u56FE\u4E66\u4EF7\u683C",
"\u56FE\u4E66\u63CF\u8FF0", "\u56FE\u4E66\u7C7B\u522B" }) {


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