——————————DescriptionStart——————————
运行环境 Java≥8、MySQL≥5.7
开发工具 eclipse/idea/myeclipse/sts等均可配置运行
适用 课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于java的Swing+MySQL图书管理系统图书借阅(java+swing+mysql)
管理员: admin 123456
用户: Jerry 123456 Tom 123456
图书管理系统 图书管理系统进行了对图书的增删改查,对用户的增删改,分为用户和管理员两个界面,管理员比用户多了两个选项卡来进行账户和图书的管理
——————————CodeStart——————————
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 model.addColumn("日期" , new Vector<Date>()); model.addColumn("借阅状态" , new Vector<String>()); JTable table = new JTable(model); jp = new JScrollPane(table); jp.setBounds(90 , 130 , 800 , 500 ); BookData bd = new BookData(); try { bd.showHistory(model, name); } catch (Exception e) { e.printStackTrace(); } JTableHeader head = table.getTableHeader(); head.setPreferredSize(new Dimension(head.getWidth(),35 )); head.setFont(new Font("宋体" ,Font.BOLD,15 )); table.setRowHeight(30 ); table.setFont(new Font("宋体" ,Font.BOLD,20 )); laypane.add(label, new Integer(0 ),0 ); laypane.add(lab, new Integer(30 ),1 ); laypane.add(jp, new Integer(130 ),2 ); label.setOpaque(false ); laypane.setOpaque(false ); } }
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 text3.setSize(dimension1); text3.setBackground(Color.pink); text3.setBounds(390 ,100 , 270 , 30 ); JButton button = new JButton("搜索" ); button.setBackground(Color.pink); button.setBounds(670 , 100 , 120 , 30 ); button.setFont(font2); model = new DefaultTableModel(); model.addColumn("书本编号" , new Vector<Integer>()); model.addColumn("书名" ,new Vector<String>()); model.addColumn("作者" ,new Vector<String>()); model.addColumn("是否在馆" ,new Vector<String>()); model.addColumn("选择图书" , new Vector<String>()); JTable table = new JTable(model); JScrollPane jp = new JScrollPane(table); jp.setBounds(100 , 150 , 750 , 450 ); BookData bd = new BookData(); try { bd.selectAll(model); } catch (Exception e2) { e2.printStackTrace(); } JTableHeader head = table.getTableHeader(); head.setPreferredSize(new Dimension(head.getWidth(),35 )); head.setFont(new Font("宋体" ,Font.BOLD,15 )); table.setRowHeight(30 ); table.setFont(new Font("宋体" ,Font.ROMAN_BASELINE,13 )); DefaultTableCellRenderer renderer=new DefaultTableCellRenderer(); renderer.setHorizontalAlignment(DefaultTableCellRenderer.CENTER);
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 Font font5 = new Font("宋体" ,Font.BOLD,25 ); password.setFont(font5); password.setBackground(Color.pink); panel4.add(password); panel4.setBounds(90 , 290 , 400 , 300 ); f.add(panel4); JButton button1 = new JButton("注册" ); JButton button2 = new JButton("登陆" ); button1.setFont(font4); button2.setFont(font4); Dimension dimension2 = new Dimension(100 ,50 ); button1.setPreferredSize(dimension2); button2.setPreferredSize(dimension2); button1.setBackground(Color.PINK); button2.setBackground(Color.PINK); panel5.add(button1); panel6.add(button2); panel5.setBounds(150 , 370 , 150 , 400 ); panel6.setBounds(330 , 370 , 150 , 400 ); f.add(panel5); f.add(panel6); id.setOpaque(false ); password.setOpaque(false ); panel1.setOpaque(false ); panel2.setOpaque(false ); panel3.setOpaque(false ); panel4.setOpaque(false ); panel5.setOpaque(false ); panel6.setOpaque(false ); f.add(jLable); select = "普通用户" ; j.addItemListener(new ItemListener() { @Override public void itemStateChanged (ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { select = (String) e.getItem(); } } }); button1.addActionListener(new ActionListener() { public void actionPerformed (ActionEvent e) {
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ConnectData cd = new ConnectData(); con = cd.connect(); ps = con.prepareStatement(sql); ps.setString(1 , username) ; rs = ps.executeQuery(); int s1=0 ; while (rs.next()) { s1 = rs.getInt(4 ); } return s1; } }
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 sm.init(); } }); button.addActionListener(new ActionListener() { public void actionPerformed (ActionEvent e) { username = textname.getText().trim(); password = textpassword.getText().trim(); repassword = textpassword1.getText().trim(); name = textname1.getText().trim(); String regex = "\\p{Alnum}" ; int t = 0 ; try { t = compare(username); } catch (Exception e2) { e2.printStackTrace(); } if (username.length() == 0 ) { JOptionPane.showMessageDialog(null , "用户名不能为空" , "警告" , JOptionPane.WARNING_MESSAGE); }else if (t == 1 ) { JOptionPane.showMessageDialog(null , "用户名已存在" , "警告" , JOptionPane.WARNING_MESSAGE); }else if ((password.length()<6 ||password.length()>12 )||password.matches(regex)) { JOptionPane.showMessageDialog(null , "输入密码不符合要求" , "警告" , JOptionPane.WARNING_MESSAGE); }else if (!(password.equals(repassword))) { JOptionPane.showMessageDialog(null , "您输入的两次密码不相同" , "警告" ,JOptionPane.ERROR_MESSAGE); }else if (name.length() == 0 ) { JOptionPane.showMessageDialog(null , "姓名不能为空" , "警告" , JOptionPane.WARNING_MESSAGE); }else { try {
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 ps.setString(1 , username); rs = ps.executeQuery(); while (rs.next()) { int BookNo = rs.getInt(1 ); String Book = rs.getString(3 ); Date Time = rs.getDate(4 ); String Lend = rs.getString(5 ); model.addRow(new Vector<>(Arrays.asList(BookNo,Book,Time,Lend))); } con.close(); } } public class ChangeInfo extends JFrame { JPanel panel = new JPanel(); private String password1; private String password2; private String password3; private String borrowname; private String borrower; private int flag = 0 ; public void setName (String borrower) { this .borrower = borrower;
——————————PayStart——————————
项目链接: https://javayms.github.io?id=501623372808201cv https://javayms.pages.dev?id=501623372808201cv