
图书管理系统。
一.项目设计到的知识
1.MVC设计模式思想(分包)
>项目分包
运用这种设计模式的优点:
MVC 是一种程序开发设计模式,它实现了显示模块与功能模块的分离。提高了程序的可维护性、可移植性、可扩展性与可重用性,降低了程序的开发难度。它主要分模型、视图、控制器三层。
>MVC简单介绍
M model业务模型(pojo/domain/bean)与现实中实体类联系
V views视图层(views)
图形化界面(gui)
C controller
用户与软件交互,处理信息
dao层(数据持久化)
提供数据
service层(处理逻辑)
处理数据
controller(javaweb里边的内容,servlet)
较详细的图示:
2.GUI(图形化界面)
其中的GUI代码案例:
package org.vector.view;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
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.JTextField;
import org.vector.bean.Book;
import org.vector.bean.Booktype;
import org.vector.bean.Borrowbook;
import org.vector.bean.Reader;
import org.vector.bean.Readertype;
import org.vector.bean.Users;
import org.vector.serviceImpl.UsersServiceImpl;
public class BookLogin extends JFrame{
public BookLogin() {
buliding();
addListeners();
}
public static String name1;
public static List<Users> list = new ArrayList<Users>();
public static List<Reader> list1 = new ArrayList<Reader>();
public static List<Book> list2 = new ArrayList<Book>();
public static List<Readertype> list3 = new ArrayList<Readertype>();
public static List<Booktype> list4 = new ArrayList<Booktype>();
public static List<Borrowbook> list5 = new ArrayList<Borrowbook>();
private JButton login,reset,register;
private JLabel name,password,label;
private JTextField name_Text;
private JPasswordField password_Text;
private void buliding() {
// TODO Auto-generated method stub
setLayout(null);
background();
setTitle("图书借阅系统登录界面");
Font font = new Font("圆体", Font.BOLD, 50);
label = new JLabel("图书借阅系统");
label.setFont(font);
label.setBounds(40, 20, 400, 50);
add(label);
name = new JLabel("用户名:");
name.setBounds(45, 100, 120, 30);
add(name);
name_Text = new JTextField(20);
name_Text.setBounds(100, 100, 200, 30);
add(name_Text);
password = new JLabel("密 码:");
password.setBounds(45, 150, 120, 30);
add(password);
password_Text = new JPasswordField(20);
password_Text.setBounds(100, 150, 200, 30);
add(password_Text);
login = new JButton("登录");
login.setBounds(50, 200, 100, 35);
add(login);
reset = new JButton("重置");
reset.setBounds(150, 200, 100, 35);
add(reset);
// register = new JButton("注册");
// register.setBounds(250, 200, 100, 35);
// add(register);
setBounds(400,300,400,300);
setLocation((2000-getWidth())/2,(1000-getHeight())/2);
setResizable(false);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setVisible(true);
}
public void background() {
setSize(600, 500);
setLocation(100, 100);
String path = "Login.jpg";
ImageIcon background = new ImageIcon(path);
JLabel label = new JLabel(background);
label.setBounds(0, 0, this.getWidth(), this.getHeight());
JPanel imagePanel = (JPanel) this.getContentPane();
imagePanel.setOpaque(false);
this.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private void addListeners() {
login.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
login.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
int flag = 0;
String name = name_Text.getText();
String password = password_Text.getText();
name1 = name;
UsersServiceImpl user = new UsersServiceImpl();
BookLogin.list.clear();
BookLogin.list.addAll(user.findUsers());
for (int i = 0; i < BookLogin.list.size(); i++) {
if(name.equals(BookLogin.list.get(i).getName())&&password.equals(BookLogin.list.get(i).getPassword())){
JOptionPane.showMessageDialog(null, "登录成功", "标题", JOptionPane.WARNING_MESSAGE);
BookLogin.this.dispose();
new BorrowbookView().setVisible(true);
flag = 1;
BookLogin.this.dispose();
new BorrowbookView().setVisible(true);
break;
}
}
if(flag == 0) {
JOptionPane.showMessageDialog(null, "登录失败,该用户不存在", "标题", JOptionPane.WARNING_MESSAGE);
}
}
});
reset.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
BookLogin.this.dispose();
new BookLogin().setVisible(true);
}
});
// register.addActionListener(new ActionListener() {
//
// @Override
// public void actionPerformed(ActionEvent e) {
// // TODO Auto-generated method stub
// BookLogin.this.dispose();
// new UserAdd().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
- 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
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
3.JDBC连接MySql数据库
用了c3p0对原生JDBC的封装思想,大大提高了开发者的效率。
c3p0xml配置文件
<?xml version="1.0" encoding="UTF-8"?>
<c3p0-config>
<!-- c3p0默认配置,下面还可以配置多个数据库 -->
<default-config>
<property name="jdbcUrl">jdbc:mysql://localhost:3306/mybook?characterEncoding=UTF8
</property>
<property name="driverClass">com.mysql.jdbc.Driver</property>
<property name="user">root</property>
<property name="password">password</property>
<property name="initialPoolSize">6</property>
<property name="maxPoolSize">10</property>
<property name="maxIdleTime">10000</property>
</default-config>
</c3p0-config>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
大多数情况下只用改,数据库名,账号,密码,别的默认值就行。
4.I/O流
I/O流是开发过程中,最耗费,最占用资源的一门技术,在开发中尽量减少对I/O的使用。
5.面向对象思想
面向对象的思想是在整个学java期间,都不断去学习,这种思想是潜移默化的,短时间内,往往难以清楚地理解。
项目运行效果
登录界面
主界面
…绅士们,请收回你们的目光。
读者信息管理
读者信息添加
读者信息查询和修改
读者信息查询
查询成功!
读者信息修改
修改成功!
图书信息管理
图书信息添加
由于东西较多,后面的我就不一一演示了,大家有兴趣的可以自己做一个更好的。
图书信息查询
图书信息修改
图书借阅管理
图书借阅
图书归还
基础信息维护
图书类别设置
读者类别设置
罚金设置
用户管理
修改密码
用户添加
用户删除
详细的可以了解,资源里边的项目。
原文章:https://blog.csdn.net/Burial_DH/article/details/112135761