1、项目功能演示
DC00026基于java Swing图书管理系统图书借阅管理系统GUI界面Java项目MySQL
2、项目功能描述
基于java swing+MySQL图书管理系统分为用户和系统管理员两个角色。
2.1 用户功能
1、用户登录、用户注册
2、个人信息查看
3、图书借阅、图书归还
2.2 系统管理员功能
1、系统登录
2、图书管理:图书新增、图书删除
3、账户中心:添加管理员、删除管理员、删除用户
3、项目运行截图
4、项目核心代码
4.1 登录窗口
package library;import java.awt.event.*;
import javax.swing.*;import java.sql.*;
import java.awt.*;
public class login extends JFrame implements ActionListener {JLabel label1 = new JLabel("用户名");JLabel label2 = new JLabel("密码");JButton button1 = new JButton("确认");JTextField textField1 = new JTextField();JPasswordField password = new JPasswordField();connectdt jdbc = new connectdt();String user , pass , table1,title;Connection conn = jdbc.conn;Statement stmt = jdbc.stmt;String st1=null;JPanel jpl;JLabel lblBackground=new JLabel(new ImageIcon("image/登陆界面.jpg"));public login(String p1,String p2,String p3,String p4) {this.table1=p1;this.user=p2;this.pass=p3;this.title=p4;init();setVisible(true);setLocation(500, 150);setSize(300, 300);setTitle(title);setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);// 当写EXIT_ON_CLOSE时,点击关闭,会关闭所有窗口setResizable(false);}public void init() {setLayout(null);label1.setBounds(40, 30, 50, 30);add(label1);textField1.setBounds(90, 30, 150, 30);add(textField1);label2.setBounds(40, 130, 50, 30);add(label2);password.setBounds(90, 130, 150, 30);add(password);button1.setBounds(90, 200, 150, 30);add(button1);lblBackground.setBounds(0, 0, 300, 300);add(lblBackground);textField1.addActionListener(this);password.addActionListener(this);button1.addActionListener(this);addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { super.windowClosing(e); //加入动作 new menu(st1);// } }); }//登陆按钮的控制,public void actionPerformed(ActionEvent e) {try {st1 = textField1.getText();String st2 = new String(password.getPassword());if (st1.length() == 0) {JOptionPane.showMessageDialog(null, "账号不能为空");return;}if (st2.length() == 0) {JOptionPane.showMessageDialog(null, "密码不能为空");return;}String sql,readerName = null;sql = "select * from " + table1 + " where " + pass + "='" + st2 + "' and "+user+" ='"+st1+"'";ResultSet rs = stmt.executeQuery(sql);if (!rs.next()) {JOptionPane.showMessageDialog(null, "账号或密码不正确");return;}else{readerName= rs.getString(2);}dispose();// 隐藏登录窗口if(title=="管理员登录"){new manager();}else{new UserMain(readerName);//返回主界面}rs.close();stmt.close();conn.close();} catch (Exception ee) {ee.printStackTrace();}}
}
4.2 注册窗口
package library;import javax.swing.*;
import java.awt.event.*;
import java.sql.*;public class register extends JFrame implements ActionListener {JLabel jlArray[] = { new JLabel("管理员编号"), new JLabel("用户名"), new JLabel("密码"), new JLabel("再次输入") };JButton button1 = new JButton("确认");JTextField jtArray[] = { new JTextField(), new JTextField(), new JTextField(), new JTextField() };String patternStr = "[0-9a-zA-Z]{6,10}",id_target="[0-9]{1,6}";//6到12位数字和字母的正则表达式,1到6位数字的正则表达式connectdt jdbc = new connectdt();//连接数据库类Connection conn = jdbc.conn;Statement stmt = jdbc.stmt;String tbname=jdbc.strtable1,username=jdbc.struser,id=jdbc.ID;public register() {init();setLocation(400, 150);setVisible(true);//设置窗口可见setSize(500, 400);setTitle("注册管理员");setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);//设置关闭当前窗口setResizable(false);//不可调整窗口尺寸}public void init() {setLayout(null);for (int i = 0; i < jtArray.length; i++) {jtArray[i].setBounds(180, 30 + 50 * i, 150, 30);add(jtArray[i]);}for (int i = 0; i < jlArray.length; i++) {jlArray[i].setBounds(110, 30 + 50 * i, 150, 30);add(jlArray[i]);}button1.setBounds(180, 250, 150, 30);add(button1);addListener();}public void addListener() {jtArray[0].addActionListener(this);jtArray[1].addActionListener(this);jtArray[2].addActionListener(this);button1.addActionListener(this);}public void actionPerformed(ActionEvent e) {try {String st1 = jtArray[0].getText();if (st1.length() == 0) {JOptionPane.showMessageDialog(null, "请输入编号");return;}if(!st1.matches(id_target)){JOptionPane.showMessageDialog(null, "编号只能是1到6位数字");return;}int n = Integer.parseInt(st1);String st2 = jtArray[1].getText();if (st2.length() == 0) {JOptionPane.showMessageDialog(null, "请输入用户名");return;}if (!st2.matches(patternStr)) {JOptionPane.showMessageDialog(null, "用户名只能是6到10位的字母或数字");return;}String st3 = jtArray[2].getText();if (st3.length() == 0) {JOptionPane.showMessageDialog(null, "请输入密码");return;}if (!st3.matches(patternStr)) {JOptionPane.showMessageDialog(null, "密码只能是6到10位的字母或数字");return;}String st4 = jtArray[3].getText();if (!st4.equals(st3)) {JOptionPane.showMessageDialog(null, "请确认密码一致");return;}String sql;sql = "select "+id+" from "+tbname+" where "+id+"=" + n;ResultSet rs = stmt.executeQuery(sql);if (rs.next()) {JOptionPane.showMessageDialog(null, "编号存在");return;}sql = "select "+username+" from "+tbname+" where "+username+"='" + st1 + "'";rs = stmt.executeQuery(sql);if (rs.next()) {JOptionPane.showMessageDialog(null, "用户名存在");return;}sql = "insert into "+tbname+" values(" + n + ",'" + st1 + "','" + st2 + "','" + st3 + "');";stmt.executeUpdate(sql);rs.close();stmt.close();conn.close();JOptionPane.showMessageDialog(null, "注册成功");dispose();} catch (Exception ee) {System.out.println("请输入数字");}}
}
4.3 管理员主界面
package library;import javax.swing.*;import java.awt.Container;
import java.awt.event.*;public class manager extends JFrame implements ActionListener {private static final long serialVersionUID = 1L;String readername; JMenuBar menubar = new JMenuBar();JMenu m1=new JMenu("图书管理");JMenu m2=new JMenu("账户中心");JMenuItem item11=new JMenuItem("增加图书",new ImageIcon("image/login.jpg"));JMenuItem item12=new JMenuItem("删除图书",new ImageIcon("image/login.jpg"));JMenuItem item21=new JMenuItem("注册新管理员",new ImageIcon("image/key.jpg"));JMenuItem item22=new JMenuItem("删除管理员",new ImageIcon("image/query.jpg"));JMenuItem item23=new JMenuItem("删除用户",new ImageIcon("image/help.jpg"));/*JMenu meArray[] = { new JMenu("图书管理"), new JMenu("账户中心"), new JMenu("帮助") };JMenuItem item[] = { new JMenuItem("增加图书"), new JMenuItem("删除图书"),new JMenuItem("注册新管理员"),new JMenuItem("删除管理员"), new JMenuItem("删除用户"), new JMenuItem("帮助信息") };*/gaintb jsp;//表格类,从数据库获取表格JScrollPane JSP;//带滚动条的列表框,用来存放jsp类里获取的表格然后添加到容器public manager() {//构造函数init();//初始化jsp = new gaintb("books");JSP = jsp.rjsp();JSP.setBounds(0, 0, 800, 550);this.add(JSP);setLocation(250, 70);setVisible(true);setSize(800, 600);setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);setResizable(false);}public void init() {setLayout(null);//格式布局为空Container c=getContentPane();c.add(menubar);menubar.add(m1);menubar.add(m2);setTitle("后台管理中心");//设置标题m1.add(item11);m1.add(item12);item11.addActionListener(this);item12.addActionListener(this);m2.add(item21);m2.add(item22);m2.add(item23);item21.addActionListener(this);item22.addActionListener(this);item23.addActionListener(this);/*meArray[0].add(item[0]);//菜单添加部件meArray[0].add(item[1]);meArray[1].add(item[2]);meArray[1].add(item[3]);meArray[1].add(item[4]);meArray[2].add(item[5]);for (int i = 0; i < meArray.length; i++) {menubar.add(meArray[i]);//将以上部件加入菜单条}*/setJMenuBar(menubar);//将菜单条放入布局里
// addListener();//添加监听的函数}/* public void addListener() {for (int i = 0; i < item.length; i++) {item[i].addActionListener(this);//依次给菜单部件加监听}}*/public void actionPerformed(ActionEvent e) {try {//e.getSource()为响应事件,以下语句为当响应事件为菜单的哪一个部件if (e.getSource() == item11) {//增加图书new addook();} else if (e.getSource() == item12) {//删除图书new delete("books");} else if (e.getSource() == item21) {//注册新管理员new register();} else if (e.getSource() == item22) {//删除管理员new delete("admindt");}else if(e.getSource()==item23){//删除用户new delete("readers");}} catch (Exception ee) {ee.printStackTrace();//抛出异常}}
}
5、项目内容包含
6、项目获取
6.1 方式一
项目文件获取:点击此处
6.2 方式二
扫描下方名片获取项目文件