commit 8e6dfb275bc57208d2a0fa1d8afdac1bb9e44cea Author: msksbr Date: Wed Jun 26 23:23:25 2024 +0800 项目重启 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d98841a --- /dev/null +++ b/.gitignore @@ -0,0 +1,26 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +# My own password +src/com/msksbr/SQL/PassWord.java \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..35410ca --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml +# 基于编辑器的 HTTP 客户端请求 +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..8916daf --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/flatlaf_3_2.xml b/.idea/libraries/flatlaf_3_2.xml new file mode 100644 index 0000000..a2dd876 --- /dev/null +++ b/.idea/libraries/flatlaf_3_2.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/mysql_connector_j_8_4_0.xml b/.idea/libraries/mysql_connector_j_8_4_0.xml new file mode 100644 index 0000000..ef93e85 --- /dev/null +++ b/.idea/libraries/mysql_connector_j_8_4_0.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/mysql_connector_j_8_4_0__2_.xml b/.idea/libraries/mysql_connector_j_8_4_0__2_.xml new file mode 100644 index 0000000..eba3bbc --- /dev/null +++ b/.idea/libraries/mysql_connector_j_8_4_0__2_.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/mysql_connector_j_8_4_0__3_.xml b/.idea/libraries/mysql_connector_j_8_4_0__3_.xml new file mode 100644 index 0000000..0f3206f --- /dev/null +++ b/.idea/libraries/mysql_connector_j_8_4_0__3_.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/mysql_connector_j_8_4_0__4_.xml b/.idea/libraries/mysql_connector_j_8_4_0__4_.xml new file mode 100644 index 0000000..f696bd6 --- /dev/null +++ b/.idea/libraries/mysql_connector_j_8_4_0__4_.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/mysql_connector_j_8_4_0__5_.xml b/.idea/libraries/mysql_connector_j_8_4_0__5_.xml new file mode 100644 index 0000000..76ca74a --- /dev/null +++ b/.idea/libraries/mysql_connector_j_8_4_0__5_.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/mysql_connector_j_8_4_0__6_.xml b/.idea/libraries/mysql_connector_j_8_4_0__6_.xml new file mode 100644 index 0000000..df57474 --- /dev/null +++ b/.idea/libraries/mysql_connector_j_8_4_0__6_.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..4731638 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..873a8ca --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..618a90a --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..cd4b02e --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 御坂昴 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/icon/icon_2048.png b/icon/icon_2048.png new file mode 100644 index 0000000..fc3459f Binary files /dev/null and b/icon/icon_2048.png differ diff --git a/icon/mainIcon.png b/icon/mainIcon.png new file mode 100644 index 0000000..a2a7249 Binary files /dev/null and b/icon/mainIcon.png differ diff --git a/icon/mainIcon.psd b/icon/mainIcon.psd new file mode 100644 index 0000000..23643dc Binary files /dev/null and b/icon/mainIcon.psd differ diff --git a/src/com/msksbr/LoginFrm/LoginFrm.form b/src/com/msksbr/LoginFrm/LoginFrm.form new file mode 100644 index 0000000..5b4b6d8 --- /dev/null +++ b/src/com/msksbr/LoginFrm/LoginFrm.form @@ -0,0 +1,128 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/msksbr/LoginFrm/LoginFrm.java b/src/com/msksbr/LoginFrm/LoginFrm.java new file mode 100644 index 0000000..617e930 --- /dev/null +++ b/src/com/msksbr/LoginFrm/LoginFrm.java @@ -0,0 +1,118 @@ +package com.msksbr.LoginFrm; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.sql.ResultSet; +import java.sql.SQLException; + +import com.msksbr.MainFrm.MainFrm; +import com.msksbr.SQL.Connector; + +public class LoginFrm extends javax.swing.JFrame { + private final Connector connector; + private final LoginMessangeExpection loginMessangeExpection; + private JPanel panel1; + private JPanel titlePanel; + private JLabel titleLabel; + private JPanel bodyPanel; + private JPanel bottomPanel; + private JButton commitButton; + private JPanel labelPanel; + private JPanel fieldPanel; + private JPanel uLabelPanel; + private JPanel pLabelPanel; + private JLabel uLabel; + private JLabel pLabel; + private JTextField uField; + private JPasswordField pField; + private String username; + private String password; + + public LoginFrm() { + loginMessangeExpection = new LoginMessangeExpection(); + + try { + connector = new Connector(); + } catch (ClassNotFoundException | SQLException e) { + throw new RuntimeException(e); + } + + setTitle("登录到图书管理系统"); + setContentPane(panel1); + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + pack(); + setVisible(true); + setSize(400, 250); + setResizable(false); + + Dimension fieldDimension = new Dimension(250, 30); + this.uField.setPreferredSize(fieldDimension); + this.pField.setPreferredSize(fieldDimension); + + this.pField.addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_ENTER) { + loginMessangeEntered(); + } + } + }); + + this.commitButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + this.commitButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + loginMessangeEntered(); + } + }); + + setLocation(); + setDialogLocation(); + } + + private void setLocation() { + ScreenSize screenSize = new ScreenSize(); + setLocation(screenSize.width / 2 - getWidth() / 2, screenSize.height / 2 - getHeight() / 2); + } + + private void setDialogLocation() { + loginMessangeExpection.setLocation(getX() + getWidth() / 4, getY() + getHeight() / 4); + } + + private void loginMessangeEntered() { + username = uField.getText(); + password = new String(pField.getPassword()); + Boolean ISMessageTrue = isLoginMessageTrue(); + if (ISMessageTrue) { + dispose(); + try { + new MainFrm(); + } catch (SQLException e) { + throw new RuntimeException(e); + } catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } + } else { + loginMessangeExpection.setVisible(true); + } + } + + private Boolean isLoginMessageTrue() { + try { + ResultSet resultSet = connector.executeQuery("SELECT * FROM users WHERE username = '" + username + "'"); + if (resultSet != null && resultSet.next()) { // 检查结果集是否不为空 + if (resultSet.getString("password").equals(password)) { + return true; + } + } + return false; + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + + +} diff --git a/src/com/msksbr/LoginFrm/LoginMessangeExpection.form b/src/com/msksbr/LoginFrm/LoginMessangeExpection.form new file mode 100644 index 0000000..e0f98e6 --- /dev/null +++ b/src/com/msksbr/LoginFrm/LoginMessangeExpection.form @@ -0,0 +1,58 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/msksbr/LoginFrm/LoginMessangeExpection.java b/src/com/msksbr/LoginFrm/LoginMessangeExpection.java new file mode 100644 index 0000000..646dde6 --- /dev/null +++ b/src/com/msksbr/LoginFrm/LoginMessangeExpection.java @@ -0,0 +1,51 @@ +package com.msksbr.LoginFrm; + +import javax.swing.*; +import java.awt.event.*; + +public class LoginMessangeExpection extends JDialog { + private JPanel contentPane; + private JButton buttonOK; + + public LoginMessangeExpection() { + setContentPane(contentPane); + setModal(true); + getRootPane().setDefaultButton(buttonOK); + setResizable(false); + setSize(200, 150); + + setTitle("登录失败"); + + buttonOK.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + onOK(); + onCancel(); + } + }); + + // 点击 X 时调用 onCancel() + setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); + addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + onCancel(); + } + }); + + // 遇到 ESCAPE 时调用 onCancel() + contentPane.registerKeyboardAction(new ActionListener() { + public void actionPerformed(ActionEvent e) { + onCancel(); + } + }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); + } + + private void onOK() { + // 在此处添加您的代码 + dispose(); + } + + private void onCancel() { + // 必要时在此处添加您的代码 + dispose(); + } +} diff --git a/src/com/msksbr/LoginFrm/ScreenSize.java b/src/com/msksbr/LoginFrm/ScreenSize.java new file mode 100644 index 0000000..71f7615 --- /dev/null +++ b/src/com/msksbr/LoginFrm/ScreenSize.java @@ -0,0 +1,15 @@ +package com.msksbr.LoginFrm; + +import java.awt.*; + +public class ScreenSize { + public int width; + public int height; + public Dimension screenSize; + + public ScreenSize() { + screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + width = screenSize.width; + height = screenSize.height; + } +} diff --git a/src/com/msksbr/Main/Main.java b/src/com/msksbr/Main/Main.java new file mode 100644 index 0000000..1c47e0d --- /dev/null +++ b/src/com/msksbr/Main/Main.java @@ -0,0 +1,21 @@ +package com.msksbr.Main; + +import com.formdev.flatlaf.FlatDarculaLaf; + +import com.msksbr.LoginFrm.LoginFrm; +import com.msksbr.MainFrm.MainFrm; + +import java.sql.SQLException; + +public class Main { + public static void main(String[] args) { + + FlatDarculaLaf.install(); + //new LoginFrm(); + try { + new MainFrm(); + } catch (SQLException | ClassNotFoundException e) { + throw new RuntimeException(e); + } + } +} diff --git a/src/com/msksbr/Main/test.java b/src/com/msksbr/Main/test.java new file mode 100644 index 0000000..f9a10f5 --- /dev/null +++ b/src/com/msksbr/Main/test.java @@ -0,0 +1,12 @@ +package com.msksbr.Main; + +import com.msksbr.MainFrm.MainFrm; +import com.msksbr.SQL.Connector; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class test { + public static void main(String[] args) { + } +} diff --git a/src/com/msksbr/MainFrm/MainFrm.form b/src/com/msksbr/MainFrm/MainFrm.form new file mode 100644 index 0000000..2bc4d18 --- /dev/null +++ b/src/com/msksbr/MainFrm/MainFrm.form @@ -0,0 +1,40 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/com/msksbr/MainFrm/MainFrm.java b/src/com/msksbr/MainFrm/MainFrm.java new file mode 100644 index 0000000..8baabca --- /dev/null +++ b/src/com/msksbr/MainFrm/MainFrm.java @@ -0,0 +1,83 @@ +package com.msksbr.MainFrm; + +import javax.swing.*; + +import com.msksbr.LoginFrm.ScreenSize; +import com.msksbr.SQL.Connector; + +import java.awt.event.*; +import java.sql.ResultSet; +import java.sql.SQLException; + +public class MainFrm extends JFrame { + private Connector connector; + private JPanel panel1; + private JPanel tablePanel; + private JPanel bottomPanel; + private JLabel backLabel; + private JLabel countMessage = new JLabel(); + private MenuBar menuBar; + + public MainFrm() throws SQLException, ClassNotFoundException { + connector = new Connector(); + setTitle("图书管理系统"); + setContentPane(panel1); + pack(); + + menuBar = new MenuBar(); + + + setJMenuBar(menuBar); + setDefaultCloseOperation(EXIT_ON_CLOSE); + setSize(960, 720); + setVisible(true); + + String countData = "本馆共藏书" + getCount("books") + "本,共记录学生信息" + getCount("students") + "条,已借阅" + getCount("rents") + "本书,人均借阅" + (double) getCount("rents") / getCount("students") + "本"; + countMessage.setText(countData); + bottomPanel.add(countMessage); + ImageIcon imageIcon = new ImageIcon("src/com/msksbr/images/backGround.png"); + addComponentListener(new ComponentAdapter() { + public void componentResized(ComponentEvent e) { + int imageSize = getWidth() < getHeight() ? getWidth() : getHeight(); + imageIcon.setImage(imageIcon.getImage().getScaledInstance(imageSize / 2, imageSize / 2, 0)); + } + }); + int imageSize = getWidth() < getHeight() ? getWidth() : getHeight(); + imageIcon.setImage(imageIcon.getImage().getScaledInstance(imageSize / 2, imageSize / 2, 0)); + + backLabel.setIcon(imageIcon); + + setLocation(); + initDialogs(); + } + + + private void setLocation() { + ScreenSize screenSize = new ScreenSize(); + setLocation(screenSize.width / 2 - getWidth() / 2, screenSize.height / 2 - getHeight() / 2); + } + + + private void initDialogs() { + menuBar.exitItem.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e) { + System.exit(0); + } + } + ); + } + + private int getCount(String table) throws SQLException { + ResultSet rs = connector.executeQuery("SELECT COUNT(*) FROM " + table + ";"); + rs.next(); + return rs.getInt("COUNT(*)"); + } + + public int getBookMaxID() throws SQLException { + ResultSet rs = connector.executeQuery("SELECT MAX(book_id) FROM books;"); + rs.next(); + return rs.getInt("MAX(book_id)"); + } + +} diff --git a/src/com/msksbr/MainFrm/MenuBar.java b/src/com/msksbr/MainFrm/MenuBar.java new file mode 100644 index 0000000..781b945 --- /dev/null +++ b/src/com/msksbr/MainFrm/MenuBar.java @@ -0,0 +1,98 @@ +package com.msksbr.MainFrm; + +import com.msksbr.MainFrm.MenuItemDiaog.Adder.StudentAdder; +import com.msksbr.MainFrm.MenuItemDiaog.AuthorDIalog; +import com.msksbr.MainFrm.MenuItemDiaog.SearchDIalog; +import com.msksbr.MainFrm.MenuItemDiaog.aboutDIalog; + +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class MenuBar extends JMenuBar { + public JMenuItem exitItem; + protected com.msksbr.MainFrm.MenuItemDiaog.aboutDIalog aboutDIalog; + protected AuthorDIalog authorDIalog; + + public MenuBar() { + // “文件“菜单 + JMenu fileMenu = new JMenu("文件"); + exitItem = new JMenuItem("退出"); + fileMenu.add(exitItem); + + // ”查询“菜单 + JMenu searchMenu = new JMenu("查询"); + JMenuItem bookSearch = new JMenuItem("查询图书信息"); + bookSearch.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + new SearchDIalog("books"); + } + } + ); + JMenuItem studentSearch = new JMenuItem("查询学生信息"); + studentSearch.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + new SearchDIalog("students"); + } + }); + JMenuItem rentSearch = new JMenuItem("查询借阅信息"); + rentSearch.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + new SearchDIalog("rents"); + } + }); + searchMenu.add(bookSearch); + searchMenu.add(studentSearch); + searchMenu.add(rentSearch); + + // ”添加“菜单 + JMenu addMenu = new JMenu("添加"); + JMenuItem bookAdd = new JMenuItem("添加图书信息"); + JMenuItem studentAdd = new JMenuItem("添加学生信息"); + studentAdd.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + new StudentAdder(); + } + }); + JMenuItem rentAdd = new JMenuItem("添加借阅信息"); + addMenu.add(bookAdd); + addMenu.add(studentAdd); + addMenu.add(rentAdd); + + // ”删除“菜单 + JMenu removeMenu = new JMenu("删除"); + JMenuItem bookRemove = new JMenuItem("删除图书信息"); + JMenuItem studentRemove = new JMenuItem("删除学生信息"); + JMenuItem rentRemove = new JMenuItem("删除借阅信息"); + removeMenu.add(bookRemove); + removeMenu.add(studentRemove); + removeMenu.add(rentRemove); + + // ”关于“菜单 + JMenu aboutMenu = new JMenu("关于"); + JMenuItem about = new JMenuItem("关于软件"); + aboutDIalog = new aboutDIalog(); + about.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + aboutDIalog.setVisible(true); + } + }); + JMenuItem author = new JMenuItem("作者"); + authorDIalog = new AuthorDIalog(); + author.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + authorDIalog.setVisible(true); + } + }); + aboutMenu.add(about); + aboutMenu.add(author); + + //将菜单加入菜单栏 + add(fileMenu); + add(searchMenu); + add(addMenu); + add(removeMenu); + add(aboutMenu); + } +} diff --git a/src/com/msksbr/MainFrm/MenuItemDiaog/Adder/StudentAdder.form b/src/com/msksbr/MainFrm/MenuItemDiaog/Adder/StudentAdder.form new file mode 100644 index 0000000..9dfa8d0 --- /dev/null +++ b/src/com/msksbr/MainFrm/MenuItemDiaog/Adder/StudentAdder.form @@ -0,0 +1,166 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/com/msksbr/MainFrm/MenuItemDiaog/Adder/StudentAdder.java b/src/com/msksbr/MainFrm/MenuItemDiaog/Adder/StudentAdder.java new file mode 100644 index 0000000..7d16cb6 --- /dev/null +++ b/src/com/msksbr/MainFrm/MenuItemDiaog/Adder/StudentAdder.java @@ -0,0 +1,98 @@ +package com.msksbr.MainFrm.MenuItemDiaog.Adder; + +import com.msksbr.LoginFrm.ScreenSize; +import com.msksbr.SQL.Connector; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.sql.ResultSet; +import java.sql.SQLException; + +public class StudentAdder extends JDialog { + private JPanel contentPane; + private JButton buttonOK; + private JTextField textField1; + private JTextField IDField; + private JTextField textField3; + private JRadioButton maleRadioButton; + private JRadioButton femaleRadioButton; + private Connector connector; + private String sName; + private int sID; + private String sClass; + private String sGender; + private ButtonGroup genderGroup; + private String sql; + + public StudentAdder() { + + try { + connector = new Connector(); + } catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } catch (SQLException e) { + throw new RuntimeException(e); + } + + genderGroup = new ButtonGroup(); + genderGroup.add(maleRadioButton); + genderGroup.add(femaleRadioButton); + + buttonOK.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + onOK(); + } + }); + + try { + sID = getStudentMaxID() + 1; + IDField.setText(String.valueOf(sID)); + } catch (SQLException e) { + throw new RuntimeException(e); + } + IDField.setEditable(false); + + setTitle("添加学生信息"); + setContentPane(contentPane); + setModal(true); + getRootPane().setDefaultButton(buttonOK); + + setSize(new Dimension(260, 265)); + setResizable(false); + pack(); + setLocation(); + setVisible(true); + + } + + public void setLocation() { + setLocation(new ScreenSize().width / 2 - getWidth() / 2, new ScreenSize().height / 2 - getHeight() / 2); + } + + private void onOK() { + // 在此处添加您的代码 + sName = textField1.getText(); + sClass = textField3.getText(); + sGender = maleRadioButton.isSelected() ? "男" : "女"; + sql = "INSERT INTO students (student_name,student_id,student_class,student_gender) VALUES ('" + sName + "'," + sID + ",'" + sClass + "','" + sGender + "');"; + commit2SQL(); + dispose(); + } + + private void commit2SQL() { + try { + connector.executeUpdate(sql); + } catch (SQLException e) { + throw new RuntimeException(e); + } + ; + } + + public int getStudentMaxID() throws SQLException { + ResultSet rs = connector.executeQuery("SELECT MAX(student_id) FROM students;"); + rs.next(); + return rs.getInt("MAX(student_id)"); + } +} diff --git a/src/com/msksbr/MainFrm/MenuItemDiaog/AuthorDIalog.form b/src/com/msksbr/MainFrm/MenuItemDiaog/AuthorDIalog.form new file mode 100644 index 0000000..1a96f6b --- /dev/null +++ b/src/com/msksbr/MainFrm/MenuItemDiaog/AuthorDIalog.form @@ -0,0 +1,98 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/msksbr/MainFrm/MenuItemDiaog/AuthorDIalog.java b/src/com/msksbr/MainFrm/MenuItemDiaog/AuthorDIalog.java new file mode 100644 index 0000000..a8d84ac --- /dev/null +++ b/src/com/msksbr/MainFrm/MenuItemDiaog/AuthorDIalog.java @@ -0,0 +1,38 @@ +package com.msksbr.MainFrm.MenuItemDiaog; + +import com.msksbr.LoginFrm.ScreenSize; + +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class AuthorDIalog extends JDialog { + private JPanel contentPane; + private JButton buttonOK; + private JPanel iconPanel; + + public AuthorDIalog() { + setContentPane(contentPane); + setModal(false); + getRootPane().setDefaultButton(buttonOK); + setVisible(false); + JLabel authorLabel = new JLabel(); + authorLabel.setIcon(new ImageIcon("src/com/msksbr/images/AuthorProfile.jpg")); + iconPanel.add(authorLabel); + setDefaultCloseOperation(DISPOSE_ON_CLOSE); + setTitle("作者"); + buttonOK.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + dispose(); + } + }); + setResizable(false); + setAlwaysOnTop(true); + pack(); + setLocation(); + } + + public void setLocation() { + setLocation(new ScreenSize().width / 2 - getWidth() / 2, new ScreenSize().height / 2 - getHeight() / 2); + } +} diff --git a/src/com/msksbr/MainFrm/MenuItemDiaog/SearchDIalog.form b/src/com/msksbr/MainFrm/MenuItemDiaog/SearchDIalog.form new file mode 100644 index 0000000..d0fb34a --- /dev/null +++ b/src/com/msksbr/MainFrm/MenuItemDiaog/SearchDIalog.form @@ -0,0 +1,105 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/com/msksbr/MainFrm/MenuItemDiaog/SearchDIalog.java b/src/com/msksbr/MainFrm/MenuItemDiaog/SearchDIalog.java new file mode 100644 index 0000000..e8ebdd5 --- /dev/null +++ b/src/com/msksbr/MainFrm/MenuItemDiaog/SearchDIalog.java @@ -0,0 +1,116 @@ +package com.msksbr.MainFrm.MenuItemDiaog; + +import com.msksbr.LoginFrm.ScreenSize; +import com.msksbr.SQL.Connector; + +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.sql.ResultSet; +import java.sql.SQLException; + +public class SearchDIalog extends JDialog { + public JLabel messageLabel; + protected int idInt; + private JPanel contentPane; + private JButton buttonOK; + private JTextField idFIeld; + private String table; + + public SearchDIalog(String table) { + setContentPane(contentPane); + setModal(true); + getRootPane().setDefaultButton(buttonOK); + if (table.equals("books")) { + this.table = "books"; + this.setTitle("查询图书信息"); + messageLabel.setText("请输入书号:"); + } else if (table.equals("students")) { + this.table = "students"; + this.setTitle("查询学生信息"); + messageLabel.setText("请输入学号:"); + } else if (table.equals("rents")) { + this.table = "rents"; + this.setTitle("查询借阅信息"); + messageLabel.setText("请输入书号:"); + } + setListener(); + pack(); + setLocation(); + setVisible(true); + } + + private void setListener() { + buttonOK.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + onOK(); + } + }); + idFIeld.addKeyListener(new KeyAdapter() { + public void keyPressed(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_ENTER) { + onOK(); + } + } + }); + } + + private void setLocation() { + setLocation(new ScreenSize().width / 2 - getWidth() / 2, new ScreenSize().height / 2 - getHeight() / 2); + } + + private void onOK() { + ResultSet rs = SQLExe(); + String message = ""; + try { + if (rs != null && rs.next()) { + String title = ""; + if (table.equals("books")) { + message = "书名:\t" + rs.getString("book_name") + "\n类别:\t" + rs.getString("book_type") + "\n书号:\t" + rs.getInt("book_id") + "\nISBN:\t" + rs.getString("ISBN"); + title = "图书信息"; + } else if (table.equals("students")) { + message = "学生姓名:\t" + rs.getString("student_name") + "\n学号:\t" + rs.getInt("student_id") + "\n班级:\t" + rs.getString("student_class") + "\n性别:\t" + rs.getString("student_gender"); + title = "学生信息"; + } else if (table.equals("rents")) { + message = "学生姓名:\t" + rs.getString("student_name") + "\n学号:\t" + rs.getInt("student_id") + "\n班级:\t" + rs.getString("student_class") + "\n性别:\t" + rs.getString("student_gender") + "\n书名:\t" + rs.getString("book_name") + "\n书号:\t" + rs.getInt("book_id") + "\n类别:\t" + rs.getString("book_type") + "\nISBN:\t" + rs.getString("ISBN"); + title = "借阅信息"; + } + new showMessae(message, title); + } else { + JOptionPane.showMessageDialog(this, "未找到", "未找到", JOptionPane.WARNING_MESSAGE); + } + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + + private ResultSet SQLExe() { + ResultSet rs = null; + try { + idInt = Integer.valueOf(idFIeld.getText()); + Connector connector = new Connector(); + rs = connector.executeQuery(SQLExeMaker(table)); + } catch (NumberFormatException e) { + JOptionPane.showMessageDialog(this, "请输入一个整数", "错误", JOptionPane.ERROR_MESSAGE); + } catch (SQLException e) { + throw new RuntimeException(e); + } catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } + return rs; + } + + private String SQLExeMaker(String table) { + if (table.equals("books")) { + return "SELECT * FROM `books` WHERE `book_id` = " + idInt + ";"; + } else if (table.equals("students")) { + return "SELECT * FROM `students` WHERE `student_id` = " + idInt + ";"; + } else if (table.equals("rents")) { + return "SELECT * FROM `rents` WHERE `book_id` = " + idInt + ";"; + } else { + return null; + } + } +} diff --git a/src/com/msksbr/MainFrm/MenuItemDiaog/aboutDIalog.form b/src/com/msksbr/MainFrm/MenuItemDiaog/aboutDIalog.form new file mode 100644 index 0000000..e8831e2 --- /dev/null +++ b/src/com/msksbr/MainFrm/MenuItemDiaog/aboutDIalog.form @@ -0,0 +1,88 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/msksbr/MainFrm/MenuItemDiaog/aboutDIalog.java b/src/com/msksbr/MainFrm/MenuItemDiaog/aboutDIalog.java new file mode 100644 index 0000000..9346a8e --- /dev/null +++ b/src/com/msksbr/MainFrm/MenuItemDiaog/aboutDIalog.java @@ -0,0 +1,44 @@ +package com.msksbr.MainFrm.MenuItemDiaog; + +import com.msksbr.LoginFrm.ScreenSize; + +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class aboutDIalog extends JDialog { + private JPanel contentPane; + private JButton buttonOK; + private JPanel iconPanel; + + public aboutDIalog() { + setTitle("关于图书管理系统"); + setVisible(false); + setContentPane(contentPane); + setModal(true); + getRootPane().setDefaultButton(buttonOK); + setResizable(false); + JLabel iconLabel = new JLabel(); + iconLabel.setIcon(new ImageIcon("src/com/msksbr/images/logo_128.png")); + iconPanel.add(iconLabel); + setModal(false); + setAlwaysOnTop(true); + + buttonOK.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + onOK(); + } + }); + pack(); + setLocation(); + } + + private void onOK() { + // 在此处添加您的代码 + dispose(); + } + + public void setLocation() { + setLocation(new ScreenSize().width / 2 - getWidth() / 2, new ScreenSize().height / 2 - getHeight() / 2); + } +} diff --git a/src/com/msksbr/MainFrm/MenuItemDiaog/showMessae.form b/src/com/msksbr/MainFrm/MenuItemDiaog/showMessae.form new file mode 100644 index 0000000..396b421 --- /dev/null +++ b/src/com/msksbr/MainFrm/MenuItemDiaog/showMessae.form @@ -0,0 +1,68 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/com/msksbr/MainFrm/MenuItemDiaog/showMessae.java b/src/com/msksbr/MainFrm/MenuItemDiaog/showMessae.java new file mode 100644 index 0000000..41b4394 --- /dev/null +++ b/src/com/msksbr/MainFrm/MenuItemDiaog/showMessae.java @@ -0,0 +1,41 @@ +package com.msksbr.MainFrm.MenuItemDiaog; + +import com.msksbr.LoginFrm.ScreenSize; + +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class showMessae extends JDialog { + private JPanel contentPane; + private JButton buttonOK; + private JTextPane textPane1; + + public showMessae(String message, String title) { + setContentPane(contentPane); + setModal(true); + getRootPane().setDefaultButton(buttonOK); + + buttonOK.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + onOK(); + } + }); + this.textPane1.setText(message); + this.setTitle(title); + textPane1.setEditable(false); + pack(); + setResizable(false); + setCenterLocation(); + setVisible(true); + } + + public void setCenterLocation() { + setLocation(new ScreenSize().width / 2 - getWidth() / 2, new ScreenSize().height / 2 - getHeight() / 2); + } + + private void onOK() { + // 在此处添加您的代码 + dispose(); + } +} diff --git a/src/com/msksbr/SQL/Connector.java b/src/com/msksbr/SQL/Connector.java new file mode 100644 index 0000000..103f372 --- /dev/null +++ b/src/com/msksbr/SQL/Connector.java @@ -0,0 +1,24 @@ +package com.msksbr.SQL; + +import java.sql.*; + +public class Connector { + private Connection conn; + private Statement stmt; + private String url = "jdbc:mysql://localhost:3306/book"; + private String user = "root"; + + public Connector() throws ClassNotFoundException, SQLException { + Class.forName("com.mysql.cj.jdbc.Driver"); + conn = DriverManager.getConnection(url, user, new PassWord().passWord); + stmt = conn.createStatement(); + } + + public ResultSet executeQuery(String query) throws SQLException { + return stmt.executeQuery(query); + } + + public int executeUpdate(String query) throws SQLException { + return stmt.executeUpdate(query); + } +} diff --git a/src/com/msksbr/images/AuthorProfile.jpg b/src/com/msksbr/images/AuthorProfile.jpg new file mode 100644 index 0000000..3164efd Binary files /dev/null and b/src/com/msksbr/images/AuthorProfile.jpg differ diff --git a/src/com/msksbr/images/backGround.png b/src/com/msksbr/images/backGround.png new file mode 100644 index 0000000..669d3e8 Binary files /dev/null and b/src/com/msksbr/images/backGround.png differ diff --git a/src/com/msksbr/images/logo_128.png b/src/com/msksbr/images/logo_128.png new file mode 100644 index 0000000..436f9a2 Binary files /dev/null and b/src/com/msksbr/images/logo_128.png differ diff --git a/system-homework-in-the-library.iml b/system-homework-in-the-library.iml new file mode 100644 index 0000000..a80f8af --- /dev/null +++ b/system-homework-in-the-library.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file