1、系统整体设计
根据前期的需求描述要求,本系统的使用主要是 PC 电脑端,用户可以通过电脑浏览器使用本系统。本系统设计是基于 java swing 架构下实现的,软件服务器的运行环境为 Windows 系统、MySQL 数据库、JDK1.5 以上;用户运行环境主要是标准的 windows 环境。用户端的功能显示与功能实现采用窗体进行实现。
1.1 业务流程设计
根据需求分析,系统的角色分为管理者和普通用户两个角色,业务的流程可以分为两个分支。
2、服务器端设计
2.1 数据库服务设计
数据库是以一定方式储存在一起、能与多个用户共享、具有尽可能小的冗余度、与应用程序彼此独立的数据集合。本系统的设计是基于关系型数据库设计的,可以使用 MySQL 开源的关系型数据库。数据库服务设计主要是设计数据实体和数 据表。
2.2 数据实体设计
根据系统的需求分析,系统中需要包含的实体对象包括用户、图书、类别和借阅信息。用户这个实体包含的信息主要有唯一性 ID 标识、密码、姓名、性别,其中1用户的角色只有用户包含有全部的属性,而管理者只包含唯一性 ID 标识和密码。
3、系统功能实现
3.1 登录功能模块的实现
根据需求分析,系统的角色分为管理者和普通,因此系统登录功能模块需要为这两个角色提供进入本系统的入口。登录模块的具体实现思想是取出输入的用户名、密码与选择的角色类型,依据角色类查询数据库服务器中对应的数据表中是否存在有与输入用户名和密码相一致的记录。如果有就重定向进入相应的管理页面;如果没有就携带失败参数重定向到登录页面,由登陆页面在加载时对参数的信息进行合理的信息提示。登录模块功能页面。
public LoginFrm() {
this.jf.getContentPane().setFont(new Font("幼圆", 1, 14));
this.jf.setBounds(600, 250, 600, 467);
this.jf.setDefaultCloseOperation(3);
this.jf.getContentPane().setLayout((LayoutManager)null);
JLabel lblNewLabel = new JLabel(new ImageIcon(LoginFrm.class.getResource("/tupian/ad1.jpg")));
lblNewLabel.setBounds(24, 10, 430, 218);
this.jf.getContentPane().add(lblNewLabel);
JLabel label = new JLabel("用户名:");
label.setFont(new Font("幼圆", 1, 14));
label.setBounds(129, 250, 60, 29);
this.jf.getContentPane().add(label);
this.userNameText = new JTextField();
this.userNameText.setBounds(199, 252, 127, 25);
this.jf.getContentPane().add(this.userNameText);
this.userNameText.setColumns(10);
JLabel label_1 = new JLabel("密码:");
label_1.setFont(new Font("幼圆", 1, 14));
label_1.setBounds(144, 289, 45, 29);
this.jf.getContentPane().add(label_1);
this.passwordText = new JPasswordField();
this.passwordText.setColumns(10);
this.passwordText.setBounds(199, 291, 127, 25);
this.jf.getContentPane().add(this.passwordText);
JLabel label_2 = new JLabel("权限:");
label_2.setFont(new Font("幼圆", 1, 14));
label_2.setBounds(144, 328, 45, 29);
this.jf.getContentPane().add(label_2);
this.comboBox = new JComboBox();
this.comboBox.setBounds(199, 332, 127, 25);
this.comboBox.addItem("用户");
this.comboBox.addItem("管理员");
this.jf.getContentPane().add(this.comboBox);
JButton button = new JButton("GO");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
LoginFrm.this.checkLogin(e);
}
});
button.setBounds(153, 377, 65, 29);
JButton button2 = new JButton("注册");
button2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
LoginFrm.this.jf.dispose();
new RegFrm();
}
});
button2.setBounds(253, 377, 65, 29);
this.jf.getContentPane().add(button);
this.jf.getContentPane().add(button2);
this.jf.setSize(500, 500);
this.jf.setLocationRelativeTo((Component)null);
this.jf.setResizable(false);
this.jf.setLayout((LayoutManager)null);
this.jf.setVisible(true);
}
3.2 注册功能模块的实现
注册模块包含用户名、密码、电话、性别等用户的基本信息,每一个输入框都有对应的校验,比如密码框,用户输入的密码就在程序中加入了正则表达式不能少于六位而且还必须带有英文字母,不然系统会给出相应提示,验证码目前是使用的随机数来进行生成的,如果用户输入的数字和随机出来的不一致,那么系统也会提示相应的错误。
public class RegFrm extends JFrame implements FocusListener {
private JPanel contentPane;
private JTextField usernameText;
private JPasswordField passwordText;
private JButton loginBtn;
private JButton regBtn;
private JFrame jf = new JFrame("图书管理系统");
private JLabel label;
private JTextField textField_1;
private JLabel userNameBel;
private JLabel pwdBel;
private JRadioButton jRadioButton1;
private JRadioButton jRadioButton2;
private JRadioButton jRadioButton3;
private JTextField userPhone;
private JTextField userVerify;
private JLabel vcodeShow;
private ButtonGroup buttonGroup;
public RegFrm() {
this.jf.setDefaultCloseOperation(3);
Container myPanel = this.jf.getContentPane();
JLabel newLabel = new JLabel("图书管理系统");
newLabel.setFont(new Font("宋体", 1, 22));
JLabel username = new JLabel("用户名:");
username.setBounds(20, 70, 80, 30);
this.usernameText = new JTextField();
this.usernameText.setBounds(100, 70, 120, 30);
this.userNameBel = new JLabel("");
this.userNameBel.setBounds(100, 92, 100, 30);
this.userNameBel.setForeground(new Color(204, 51, 51));
this.usernameText.addFocusListener(new FocusAdapter() {
public void focusLost(FocusEvent e) {
if (toolUtil.isEmpty(RegFrm.this.usernameText.getText())) {
RegFrm.this.userNameBel.setText("用户名不能为空");
} else {
RegFrm.this.userNameBel.setText("√");
RegFrm.this.userNameBel.setForeground(Color.GREEN);
}
}
});
JLabel pwd = new JLabel("密码:");
pwd.setBounds(20, 120, 80, 30);
this.passwordText = new JPasswordField();
this.passwordText.setBounds(100, 120, 120, 30);
this.pwdBel = new JLabel("");
this.pwdBel.setBounds(100, 142, 100, 30);
this.pwdBel.setForeground(new Color(204, 51, 51));
this.passwordText.addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent e) {
}
public void focusLost(FocusEvent e) {
String pwd = RegFrm.this.passwordText.getText();
if (toolUtil.isEmpty(pwd)) {
RegFrm.this.pwdBel.setText("密码不能为空");
} else {
boolean flag = pwd.matches("^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$");
if (flag) {
RegFrm.this.pwdBel.setText("√");
RegFrm.this.pwdBel.setForeground(Color.GREEN);
} else {
RegFrm.this.pwdBel.setText("密码需为6-16位数字和字母 的组合");
}
}
}
});
JLabel phoneText = new JLabel("电话:");
phoneText.setBounds(20, 167, 40, 30);
this.userPhone = new JTextField();
this.userPhone.setBounds(100, 167, 120, 30);
JLabel sexText = new JLabel("性别:");
sexText.setBounds(20, 207, 40, 30);
this.jRadioButton1 = new JRadioButton("男", true);
this.jRadioButton2 = new JRadioButton("女", false);
this.buttonGroup = new ButtonGroup();
this.buttonGroup.add(this.jRadioButton1);
this.buttonGroup.add(this.jRadioButton2);
this.jRadioButton3 = new JRadioButton();
this.jRadioButton1.setBounds(100, 207, 40, 30);
this.jRadioButton2.setBounds(150, 207, 40, 30);
JLabel verify = new JLabel("验证码:");
verify.setBounds(20, 240, 60, 30);
this.userVerify = new JTextField();
this.userVerify.setBounds(100, 240, 80, 30);
this.vcodeShow = new JLabel(this.vcodeShow());
this.vcodeShow.setBounds(190, 240, 60, 20);
this.vcodeShow.setFont(new Font("宋体", 1, 18));
this.vcodeShow.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
RegFrm.this.vcodeShow();
RegFrm.this.vcodeShow.setText(RegFrm.this.vcodeShow());
}
});
JLabel hint = new JLabel("点击换一张");
hint.setBounds(190, 240, 150, 50);
hint.setFont(new Font("宋体", 1, 10));
this.regBtn = new JButton("注册");
this.regBtn.setBounds(10, 280, 120, 30);
this.regBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
RegFrm.this.registerActionPerformed(e);
}
});
this.loginBtn = new JButton("前往登录页面");
this.loginBtn.setBounds(160, 280, 120, 30);
this.loginBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
RegFrm.this.jf.dispose();
new LoginFrm();
}
});
this.jf.add(this.usernameText);
this.jf.add(username);
this.jf.add(this.userNameBel);
this.jf.add(this.passwordText);
this.jf.add(pwd);
this.jf.add(this.pwdBel);
this.jf.add(phoneText);
this.jf.add(this.userPhone);
this.jf.add(this.jRadioButton1);
this.jf.add(this.jRadioButton2);
this.jf.add(sexText);
this.jf.add(this.vcodeShow);
this.jf.add(this.regBtn);
this.jf.add(verify);
this.jf.add(hint);
this.jf.add(this.loginBtn);
this.jf.add(this.userVerify);
this.jf.setSize(300, 500);
this.jf.setLocationRelativeTo((Component)null);
this.jf.setResizable(false);
this.jf.setLayout((LayoutManager)null);
this.jf.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (this.jRadioButton1.isSelected()) {
JOptionPane.showMessageDialog(this, "你选择男");
}
if (this.jRadioButton2.isSelected()) {
JOptionPane.showMessageDialog(this, "你选择女");
}
}
public boolean RadioControl(Boolean aFalse) {
return aFalse;
}
private String vcodeShow() {
long vcode = Math.round((Math.random() + 1.0) * 1000.0);
return String.valueOf(vcode);
}
private void loginActionPerformed(ActionEvent evt) {
String username = this.usernameText.getText().trim();
String password = this.passwordText.getText().trim();
if (username != null && !"".equals(username)) {
if (password != null && !"".equals(password)) {
Users user = new Users(username, password);
Connection con = null;
try {
try {
con = DbUtil.getConnection();
UserDao userDao = new UserDao();
userDao.addUser((com.mysql.jdbc.Connection)con, user);
this.dispose();
} catch (SQLException var12) {
var12.printStackTrace();
throw new RuntimeException("登录失败", var12);
} catch (Exception var13) {
var13.printStackTrace();
}
} finally {
;
}
} else {
JOptionPane.showMessageDialog((Component)null, "密码不能为空");
}
} else {
JOptionPane.showMessageDialog((Component)null, "用户名不能为空");
}
}
private boolean registerActionPerformed(ActionEvent evt) {
String username = this.usernameText.getText().trim();
String password = this.passwordText.getText().trim();
String phone = this.userPhone.getText().trim();
if (toolUtil.isEmpty(username)) {
JOptionPane.showMessageDialog((Component)null, "用户名不能为空!");
return false;
} else if (toolUtil.isEmpty(password)) {
JOptionPane.showMessageDialog((Component)null, "密码不能为空");
return false;
} else {
boolean flag = password.matches("^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$");
if (!flag) {
JOptionPane.showMessageDialog((Component)null, "密码需为6-16位数字和字母 的组合");
return false;
} else if (toolUtil.isEmpty(phone)) {
JOptionPane.showMessageDialog((Component)null, "电话不能为空!");
return false;
} else {
if (this.jRadioButton1.isSelected()) {
this.jRadioButton3.setText("1");
}
if (this.jRadioButton2.isSelected()) {
this.jRadioButton3.setText("0");
}
Integer sex = Integer.valueOf(this.jRadioButton3.getText().trim());
if (!this.vcodeShow.getText().equals(this.userVerify.getText())) {
JOptionPane.showMessageDialog((Component)null, "验证码输入错误!");
return false;
} else {
Users users = new Users();
users.setUserName(username);
users.setUserPwd(password);
users.setUserPhone(phone);
users.setUserSex(sex);
UserDao userDao = new UserDao();
try {
Integer addUser = userDao.addUser(DbUtil.getConnection(), users);
if (addUser == 2) {
JOptionPane.showMessageDialog((Component)null, "该用户已存在!");
boolean var9 = false;
return var9;
}
JOptionPane.showMessageDialog((Component)null, "注册成功");
} catch (Exception var13) {
var13.printStackTrace();
} finally {
DbUtil.getConnection();
}
return true;
}
}
}
}
public void focusGained(FocusEvent e) {
this.usernameText.setText("用户名不能为空");
}
public void focusLost(FocusEvent e) {
}
}
3.3 用户管理中心实现
3.3.1 普通用户登录页面展示
如果是通过普通用户登录那么就会进入到以下如图所示的页面,该页面有还书和书籍信息两大模块,用户可进行借阅查询以及归还图书。
3.4 管理员中心实现
3.4.1 管理员系统页面展示以及部分代码展示
管理员登录系统后页面如下所示,内容相较于普通用户来说较为丰富,导航栏可以看到大体分为三类,类别管理、书籍管理以及用户管理,以下展示的是书籍管理中书籍修改的功能,该功能可以修改书籍的一些基本信息,如书名、作者、价格等等,以及可以控制图书的上下架,如果图书下架了,则在用户界面用户选择图书时就没有该图书,同样也有搜索图书的功能。
3.4.2 管理员图书添加页面展示以及部分代码展示
可以添加相应的图书信息,类别列表时通过从数据库中取出的相关类别列表动态展示到下拉框里实现选择功能。
3.5 其它模块展示
3.5.1 用户管理模块
用户借阅信息。
用户信息管理。
3.5.2 借阅信息模块
书籍借阅信息查询。
3.5.3 类别添加和修改模块
添加书籍类别和修改书籍类别。