Compare commits
10 Commits
139952d7f3
...
9f2583baab
| Author | SHA1 | Date | |
|---|---|---|---|
| 9f2583baab | |||
| 368fff66d5 | |||
| c6cad66afa | |||
| 8db074f7b7 | |||
| 81d7581531 | |||
| f3da2681f3 | |||
| 10ae171a06 | |||
| 82cde2df25 | |||
| 0465908846 | |||
| 29658ccfe9 |
+7
-2
@@ -11,7 +11,6 @@
|
||||
.mtj.tmp/
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.nar
|
||||
*.ear
|
||||
@@ -23,4 +22,10 @@
|
||||
hs_err_pid*
|
||||
|
||||
# My own password
|
||||
src/com/msksbr/SQL/PassWord.java
|
||||
src/com/msksbr/SQL/PassWord.java
|
||||
|
||||
# JetBrains IDEs
|
||||
.idea/
|
||||
*/.idea/
|
||||
*.iml
|
||||
out/
|
||||
Generated
-8
@@ -1,8 +0,0 @@
|
||||
# 默认忽略的文件
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# 基于编辑器的 HTTP 客户端请求
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
Generated
-13
@@ -1,13 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile name="Maven default annotation processors profile" enabled="true">
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="system-homework-in-the-library" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
</project>
|
||||
Generated
-20
@@ -1,20 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
||||
Generated
-9
@@ -1,9 +0,0 @@
|
||||
<component name="libraryTable">
|
||||
<library name="flatlaf-3.2">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/flatlaf-3.2.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
||||
-9
@@ -1,9 +0,0 @@
|
||||
<component name="libraryTable">
|
||||
<library name="mysql-connector-j-8.4.0">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/lib/mysql-connector-j-8.4.0.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
||||
Generated
-14
@@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
-8
@@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/system-homework-in-the-library.iml" filepath="$PROJECT_DIR$/system-homework-in-the-library.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
Generated
-6
@@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="SqlDialectMappings">
|
||||
<file url="file://$PROJECT_DIR$/sql/book.sql" dialect="MariaDB" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
-127
@@ -1,127 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Palette2">
|
||||
<group name="Swing">
|
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||
</item>
|
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||
<initial-values>
|
||||
<property name="text" value="Button" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="RadioButton" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="CheckBox" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="Label" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||
<preferred-size width="-1" height="20" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
<component name="uidesigner-configuration">
|
||||
<option name="DEFAULT_LAYOUT_MANAGER" value="BorderLayout" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
-6
@@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1,130 @@
|
||||
# 图书管理系统作业
|
||||
|
||||
## 简介
|
||||
|
||||
这是一个图书管理系统的作业,使用了swing组件库和MySQL数据库,实现了图书的增删改查功能,并实现了登录功能,使用DarkLaf主题
|
||||
|
||||
## 运行
|
||||
|
||||
### 1. 下载项目
|
||||
|
||||
```bash
|
||||
git clone https://gitee.com/msksbr/system-homework-in-the-library.git
|
||||
```
|
||||
|
||||
### 2. 打开项目
|
||||
|
||||
打开clone下来的`system-homework-in-the-library`文件夹,右键使用idea打开(`Open Folder as IntelliJ IDEA Project `)
|
||||
|
||||
<img src="README.assets/image-20250206210127025.png" alt="image-20250206210127025" style="zoom:50%;" />
|
||||
|
||||
### 3. 注册库文件
|
||||
|
||||
打开项目中的`lib`文件夹,右键jar包,选择`添加为库…`
|
||||
|
||||
<img src="README.assets/image-20250206210455149.png" alt="image-20250206210455149" style="zoom:50%;" />
|
||||
|
||||
### 4. 安装插件
|
||||
|
||||
由于本项目开发时IDEA版本较旧,`Swing UI Designer`插件为内置,而在新版本的IDEA中,`Swing UI Designer`已经被移除,需要手动安装
|
||||
|
||||
插件商店页面如下:
|
||||
|
||||
<img src="README.assets/image-20250206210827934.png" alt="image-20250206210827934" style="zoom:50%;" />
|
||||
|
||||
### 5. 创建数据库
|
||||
|
||||
在您的mysql中创建一个名为`book`的数据库,并导入`book.sql`文件,字符集选择`utf8mb4`
|
||||
|
||||
`book.sql`位于项目的`sql`文件夹下
|
||||
|
||||
### 6. 编辑数据库配置
|
||||
|
||||
数据库配置位于`com.msksbr.SQL`包下的两个类中,分别是`Connector`和`PassWord`(出于隐私考虑,本人并未上传PassWord.java)
|
||||
|
||||
#### 6.1 创建PassWord类
|
||||
则首先需要创建PassWord.java文件,内容如下:
|
||||
|
||||
```java
|
||||
package com.msksbr.SQL;
|
||||
|
||||
/**
|
||||
* 密码类,用于存储数据库连接的密码。
|
||||
*/
|
||||
public class PassWord {
|
||||
// 数据库连接密码
|
||||
public String passWord = "Your_Pass_Word";
|
||||
}
|
||||
```
|
||||
|
||||
将`Your_Pass_Word`替换为您的数据库密码
|
||||
|
||||
#### 6.2 编辑Connector类
|
||||
|
||||
类中的url和user字符串需要根据您的数据库配置进行修改,其位于类中的第14行和第16行
|
||||
|
||||
```java
|
||||
// 数据库连接URL
|
||||
private String url = "jdbc:mysql://your_url:your_port/book";
|
||||
// 数据库用户名
|
||||
private String user = "your_username";
|
||||
```
|
||||
|
||||
将`your_url`和`your_port`替换为您的数据库地址和端口,将`your_username`替换为您的数据库用户名
|
||||
|
||||
### 7. 运行程序
|
||||
运行`com.msksbr.Main`类中的`main`方法,即可运行程序
|
||||
|
||||
即打开com.msksbe.Main类,在Main类上点击三角运行标志即可运行程序
|
||||
|
||||
<img src="README.assets/image-20250206212306354.png" alt="image-20250206212306354" style="zoom:50%;" />
|
||||
|
||||
## 默认用户名和密码
|
||||
|
||||
| 用户名 | 密码 |
|
||||
| ------ | ------------------ |
|
||||
| `root` | `PassWord_of_root` |
|
||||
|
||||
## 声明
|
||||
|
||||
1. 本项目完全开源免费,如您从任何渠道购买到本软件及其源码,请您立即退款,并联系作者
|
||||
|
||||
2. 本项目遵守MIT协议,您可以在遵守MIT协议的前提下使用本项目
|
||||
|
||||
- 本软件按”原样“提供,作者不负任何担保责任,也不对使用本软件的任何风险负责
|
||||
- 本软件完全可以商用,可随意进行修改、复制、再发布,但请保留原作者信息
|
||||
- 保留作者信息:在软件的每个副本或衍生作品中,都必须包含完整的作者信息,保留MIT许可证副本
|
||||
- 不得用于违法用途:不得用于任何违法、滥用或恶意的目的
|
||||
- 不得侵犯第三方权利:不得侵犯任何第三方的知识产权、商标权或其他权利
|
||||
- 不得损害作者权益:不得损害作者的名誉、形象或利益
|
||||
|
||||
严正声明:对本软件及源码及其副本进行的任何下载、克隆、再分发,都代表您已阅读并同意本声明
|
||||
|
||||
3. 任何得到本软件及其源码及其副本的人,如果是在付费渠道购买到的,都有权利使用本声明以及软件内`关于->关于软件`屏幕中的声明联系渠道进行退款
|
||||
|
||||
4. 再次强调,如果您在任何渠道购买到本软件及其源码,您可以并且有权力使用本声明以及软件内`关于->关于软件`屏幕中的声明联系渠道进行退款
|
||||
|
||||
5. 提到的`本软件及其源码及其副本`中的版本指的是本项目在gitee上的原样版本,经过修改后可以进行商用,但请保留原作者信息,**但请保留原作者信息**,**但请保留原作者信息**
|
||||
|
||||
6. 再次严正声明:对本软件及源码及其副本进行的任何下载、克隆、再分发,都代表您**已阅读并同意**本声明
|
||||
|
||||
### 作者联系方式
|
||||
|
||||
- [3141661556@qq.com](mailto://3141661556@qq.com/) 常用
|
||||
- [gugugulaocuchen@gmail.com](mailto://gugugulaocuchen@gmail.com/) 想起来就瞄一眼的那种
|
||||
- [jasoncaesar515@outlook.com](mailto://jasoncaesar515@outlook.com/) 基本不会用
|
||||
|
||||
|
||||
## 本项目的未来打算
|
||||
|
||||
这个项目说白了就是拿来水作业的,所以未来打算不会再进行维护,也不会再进行更新,其中的很多功能也非常潦草,注释都是后来用ai加的
|
||||
|
||||
为了给学弟学妹们一个免费的参考,我将本项目开源
|
||||
|
||||
之后为了更好的学习,我会将本项目使用C++,qy6和json重构,使其更加规范,更加易于维护
|
||||
|
||||
虽然上面声明显得很凶,但是如果商家售卖的是帮助你运行代码,包括帮助配置环境之类的,那么他收费是理所应得的,因为你作为一个计算机学科的学生,你连这都不会,你不花这冤枉钱谁花呢
|
||||
|
||||
最后,希望大家都能有个好成绩
|
||||
|
||||
喜欢的话记得给个star☕
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 45 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 45 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 124 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 53 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 378 KiB |
Binary file not shown.
Binary file not shown.
@@ -1,4 +0,0 @@
|
||||
# SQL配置说明
|
||||
|
||||
1. 创建名为book的数据库
|
||||
2. 导入book.sql
|
||||
@@ -13,100 +13,183 @@ import com.msksbr.MainFrm.MainFrm;
|
||||
import com.msksbr.SQL.Connector;
|
||||
import com.msksbr.images.EasterEgg;
|
||||
|
||||
/**
|
||||
* LoginFrm 类表示登录窗口,用于用户登录到图书管理系统。
|
||||
*/
|
||||
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();
|
||||
setIconImage(new ImageIcon("src/com/msksbr/images/mainicon.png").getImage());
|
||||
// 设置窗口图标
|
||||
setIconImage(new ImageIcon(LoginFrm.class.getResource("/com/msksbr/images/mainicon.png")).getImage());
|
||||
|
||||
try {
|
||||
// 创建数据库连接器
|
||||
connector = new Connector();
|
||||
} catch (ClassNotFoundException | SQLException e) {
|
||||
// 抛出运行时异常
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
// 设置窗口标题
|
||||
setTitle("登录到图书管理系统");
|
||||
// 设置内容面板
|
||||
setContentPane(panel1);
|
||||
// 设置默认关闭操作
|
||||
setDefaultCloseOperation(JFrame.EXIT_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() {
|
||||
/**
|
||||
* 当按键被按下时调用的方法。
|
||||
*
|
||||
* @param e 按键事件
|
||||
*/
|
||||
@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() {
|
||||
/**
|
||||
* 当按钮被点击时调用的方法。
|
||||
*
|
||||
* @param e 动作事件
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查登录消息是否正确。
|
||||
*
|
||||
* @return 如果登录消息正确返回 true,否则返回 false
|
||||
*/
|
||||
private Boolean isLoginMessageTrue() {
|
||||
// 如果用户名和密码是特定的彩蛋值
|
||||
if (username.equals("java") && password.equals("beans")) {
|
||||
// 显示彩蛋对话框
|
||||
new EasterEgg();
|
||||
return false;
|
||||
} else {
|
||||
try {
|
||||
// 执行查询以检查用户名和密码是否匹配
|
||||
ResultSet resultSet = connector.executeQuery("SELECT * FROM users WHERE username = '" + username + "'");
|
||||
if (resultSet != null && resultSet.next()) { // 检查结果集是否不为空
|
||||
if (resultSet.getString("password").equals(password)) {
|
||||
@@ -115,10 +198,9 @@ public class LoginFrm extends javax.swing.JFrame {
|
||||
}
|
||||
return false;
|
||||
} catch (SQLException e) {
|
||||
// 抛出运行时异常
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -3,22 +3,44 @@ package com.msksbr.LoginFrm;
|
||||
import javax.swing.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
/**
|
||||
* LoginMessangeExpection 类表示一个登录失败的对话框,用于显示错误信息。
|
||||
*/
|
||||
public class LoginMessangeExpection extends JDialog {
|
||||
// 对话框的内容面板
|
||||
private JPanel contentPane;
|
||||
// 确认按钮
|
||||
private JButton buttonOK;
|
||||
|
||||
/**
|
||||
* 构造函数,初始化 LoginMessangeExpection 对话框。
|
||||
*/
|
||||
public LoginMessangeExpection() {
|
||||
// 设置对话框的内容面板
|
||||
setContentPane(contentPane);
|
||||
// 设置对话框为模态对话框
|
||||
setModal(true);
|
||||
// 设置默认按钮为 buttonOK
|
||||
getRootPane().setDefaultButton(buttonOK);
|
||||
// 设置对话框不可调整大小
|
||||
setResizable(false);
|
||||
// 设置对话框的大小
|
||||
setSize(200, 150);
|
||||
|
||||
// 设置对话框的标题
|
||||
setTitle("登录失败");
|
||||
|
||||
// 为 buttonOK 添加动作监听器
|
||||
buttonOK.addActionListener(new ActionListener() {
|
||||
/**
|
||||
* 当按钮被点击时调用的方法。
|
||||
*
|
||||
* @param e 动作事件
|
||||
*/
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// 调用 onOK 方法
|
||||
onOK();
|
||||
// 调用 onCancel 方法
|
||||
onCancel();
|
||||
}
|
||||
});
|
||||
@@ -26,26 +48,46 @@ public class LoginMessangeExpection extends JDialog {
|
||||
// 点击 X 时调用 onCancel()
|
||||
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
||||
addWindowListener(new WindowAdapter() {
|
||||
/**
|
||||
* 当窗口关闭事件发生时调用的方法。
|
||||
*
|
||||
* @param e 窗口事件
|
||||
*/
|
||||
public void windowClosing(WindowEvent e) {
|
||||
// 调用 onCancel 方法
|
||||
onCancel();
|
||||
}
|
||||
});
|
||||
|
||||
// 遇到 ESCAPE 时调用 onCancel()
|
||||
contentPane.registerKeyboardAction(new ActionListener() {
|
||||
/**
|
||||
* 当按键事件发生时调用的方法。
|
||||
*
|
||||
* @param e 动作事件
|
||||
*/
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// 调用 onCancel 方法
|
||||
onCancel();
|
||||
}
|
||||
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当用户点击确认按钮时调用的方法。
|
||||
*/
|
||||
private void onOK() {
|
||||
// 在此处添加您的代码
|
||||
// 关闭对话框
|
||||
dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* 当用户取消操作时调用的方法。
|
||||
*/
|
||||
private void onCancel() {
|
||||
// 必要时在此处添加您的代码
|
||||
// 关闭对话框
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,14 +2,26 @@ package com.msksbr.LoginFrm;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* ScreenSize 类用于获取屏幕的尺寸信息。
|
||||
*/
|
||||
public class ScreenSize {
|
||||
// 屏幕的宽度
|
||||
public int width;
|
||||
// 屏幕的高度
|
||||
public int height;
|
||||
// 屏幕的尺寸对象
|
||||
public Dimension screenSize;
|
||||
|
||||
/**
|
||||
* 构造函数,初始化 ScreenSize 对象并获取屏幕尺寸。
|
||||
*/
|
||||
public ScreenSize() {
|
||||
// 获取默认工具包的屏幕尺寸
|
||||
screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
// 设置屏幕宽度
|
||||
width = screenSize.width;
|
||||
// 设置屏幕高度
|
||||
height = screenSize.height;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,19 @@ import com.formdev.flatlaf.FlatDarculaLaf;
|
||||
|
||||
import com.msksbr.LoginFrm.LoginFrm;
|
||||
|
||||
/**
|
||||
* 主类,程序入口
|
||||
*/
|
||||
public class Main {
|
||||
/**
|
||||
* 主方法,程序入口点
|
||||
*
|
||||
* @param args 命令行参数
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
// 安装FlatDarcula外观
|
||||
FlatDarculaLaf.install();
|
||||
// 创建并显示登录窗口
|
||||
new LoginFrm();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,52 +10,90 @@ import java.awt.event.*;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* 主窗口类,继承自JFrame,用于显示图书管理系统的主界面
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* 构造方法,初始化主窗口并设置相关属性
|
||||
* @throws SQLException 如果数据库操作失败抛出此异常
|
||||
* @throws ClassNotFoundException 如果找不到数据库驱动类抛出此异常
|
||||
*/
|
||||
public MainFrm() throws SQLException, ClassNotFoundException {
|
||||
setIconImage(new ImageIcon("src/com/msksbr/images/mainicon.png").getImage());
|
||||
// 设置窗口图标
|
||||
setIconImage(new ImageIcon(MainFrm.class.getResource("/com/msksbr/images/mainicon.png")).getImage());
|
||||
// 初始化数据库连接器
|
||||
connector = new Connector();
|
||||
// 设置窗口标题
|
||||
setTitle("图书管理系统");
|
||||
// 设置窗口内容面板
|
||||
setContentPane(panel1);
|
||||
// 调整窗口大小以适应内容
|
||||
pack();
|
||||
|
||||
// 初始化菜单栏
|
||||
menuBar = new MenuBar();
|
||||
|
||||
|
||||
// 设置窗口的菜单栏
|
||||
setJMenuBar(menuBar);
|
||||
// 设置窗口关闭操作
|
||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
// 设置窗口大小
|
||||
setSize(960, 720);
|
||||
|
||||
// 获取并设置统计信息
|
||||
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");
|
||||
imageIcon.setImage(imageIcon.getImage().getScaledInstance(250, 250, 0));
|
||||
// 创建并设置背景图片
|
||||
// 创建一个 ImageIcon 对象,用于加载背景图片
|
||||
ImageIcon imageIcon = new ImageIcon(MainFrm.class.getResource("/com/msksbr/images/backGround.png"));
|
||||
|
||||
imageIcon.setImage(imageIcon.getImage().getScaledInstance(250, 250, 0));
|
||||
// 设置背景标签的图标
|
||||
backLabel.setIcon(imageIcon);
|
||||
|
||||
// 设置窗口的最小尺寸
|
||||
setMinimumSize(new Dimension(960, 720));
|
||||
|
||||
// 设置窗口位置
|
||||
setLocation();
|
||||
// 初始化对话框
|
||||
initDialogs();
|
||||
// 设置窗口可见
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置窗口位置,使其居中显示在屏幕上
|
||||
*/
|
||||
private void setLocation() {
|
||||
// 创建一个 ScreenSize 对象,用于获取屏幕尺寸
|
||||
ScreenSize screenSize = new ScreenSize();
|
||||
// 设置窗口位置,使其居中显示在屏幕上
|
||||
setLocation(screenSize.width / 2 - getWidth() / 2, screenSize.height / 2 - getHeight() / 2);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 初始化对话框,为退出菜单项添加事件监听器
|
||||
*/
|
||||
private void initDialogs() {
|
||||
// 为退出菜单项添加事件监听器,当点击退出菜单项时,调用 System.exit(0) 方法退出程序
|
||||
menuBar.exitItem.addActionListener(
|
||||
new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
@@ -65,9 +103,18 @@ public class MainFrm extends JFrame {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定表中的记录数
|
||||
* @param table 表名
|
||||
* @return 表中的记录数
|
||||
* @throws SQLException 如果执行 SQL 查询时发生错误
|
||||
*/
|
||||
private int getCount(String table) throws SQLException {
|
||||
// 执行 SQL 查询,获取指定表中的记录数
|
||||
ResultSet rs = connector.executeQuery("SELECT COUNT(*) FROM " + table + ";");
|
||||
// 将结果集指针移动到第一行
|
||||
rs.next();
|
||||
// 返回查询结果中的记录数
|
||||
return rs.getInt("COUNT(*)");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,114 +9,161 @@ import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
/**
|
||||
* 主窗口菜单栏类,继承自JMenuBar,用于创建和管理菜单栏及其菜单项
|
||||
*/
|
||||
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");
|
||||
}
|
||||
}
|
||||
);
|
||||
@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("添加图书信息");
|
||||
// 为添加图书信息菜单项添加事件监听器,当点击时弹出图书信息添加对话框
|
||||
bookAdd.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
new BookAdder();
|
||||
}
|
||||
});
|
||||
// 创建添加学生信息菜单项
|
||||
JMenuItem studentAdd = new JMenuItem("添加学生信息");
|
||||
// 为添加学生信息菜单项添加事件监听器,当点击时弹出学生信息添加对话框
|
||||
studentAdd.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
new StudentAdder();
|
||||
}
|
||||
});
|
||||
// 创建添加借阅信息菜单项
|
||||
JMenuItem rentAdd = new JMenuItem("添加借阅信息");
|
||||
// 为添加借阅信息菜单项添加事件监听器,当点击时弹出借阅信息添加对话框
|
||||
rentAdd.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
new RentAdder();
|
||||
}
|
||||
});
|
||||
// 将添加图书信息菜单项添加到添加菜单
|
||||
addMenu.add(bookAdd);
|
||||
// 将添加学生信息菜单项添加到添加菜单
|
||||
addMenu.add(studentAdd);
|
||||
// 将添加借阅信息菜单项添加到添加菜单
|
||||
addMenu.add(rentAdd);
|
||||
|
||||
// ”删除“菜单
|
||||
JMenu removeMenu = new JMenu("删除");
|
||||
// 创建删除图书信息菜单项
|
||||
JMenuItem bookRemove = new JMenuItem("删除图书信息");
|
||||
// 为删除图书信息菜单项添加事件监听器,当点击时弹出图书信息删除对话框
|
||||
bookRemove.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
new Remover("books");
|
||||
}
|
||||
});
|
||||
// 创建删除学生信息菜单项
|
||||
JMenuItem studentRemove = new JMenuItem("删除学生信息");
|
||||
// 为删除学生信息菜单项添加事件监听器,当点击时弹出学生信息删除对话框
|
||||
studentRemove.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
new Remover("students");
|
||||
}
|
||||
});
|
||||
// 创建删除借阅信息菜单项
|
||||
JMenuItem rentRemove = new JMenuItem("删除借阅信息");
|
||||
// 为删除借阅信息菜单项添加事件监听器,当点击时弹出借阅信息删除对话框
|
||||
rentRemove.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
new Remover("rents");
|
||||
}
|
||||
});
|
||||
// 将删除图书信息菜单项添加到删除菜单
|
||||
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);
|
||||
}
|
||||
});
|
||||
// 创建MIT许可证菜单项
|
||||
JMenuItem MITLicense = new JMenuItem("MIT许可证");
|
||||
// 为MIT许可证菜单项添加事件监听器,当点击时显示MIT许可证的对话框
|
||||
MITLicense.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
new MITDialog();
|
||||
}
|
||||
});
|
||||
// 创建鸣谢菜单项
|
||||
JMenuItem thanksItem = new JMenuItem("鸣谢");
|
||||
// 为鸣谢菜单项添加事件监听器,当点击时显示鸣谢信息的对话框
|
||||
thanksItem.addActionListener(
|
||||
new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
@@ -124,16 +171,25 @@ public class MenuBar extends JMenuBar {
|
||||
}
|
||||
}
|
||||
);
|
||||
// 将关于软件菜单项添加到关于菜单
|
||||
aboutMenu.add(about);
|
||||
// 将作者菜单项添加到关于菜单
|
||||
aboutMenu.add(author);
|
||||
// 将MIT许可证菜单项添加到关于菜单
|
||||
aboutMenu.add(MITLicense);
|
||||
// 将鸣谢菜单项添加到关于菜单
|
||||
aboutMenu.add(thanksItem);
|
||||
|
||||
//将菜单加入菜单栏
|
||||
// 将文件菜单添加到菜单栏
|
||||
add(fileMenu);
|
||||
// 将查询菜单添加到菜单栏
|
||||
add(searchMenu);
|
||||
// 将添加菜单添加到菜单栏
|
||||
add(addMenu);
|
||||
// 将删除菜单添加到菜单栏
|
||||
add(removeMenu);
|
||||
// 将关于菜单添加到菜单栏
|
||||
add(aboutMenu);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,36 +6,67 @@ import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
/**
|
||||
* AcademyThanksDialog 类用于显示鸣谢信息的对话框。
|
||||
*/
|
||||
public class AcademyThanksDialog extends JDialog {
|
||||
// 内容面板
|
||||
private JPanel contentPane;
|
||||
// 确认按钮
|
||||
private JButton buttonOK;
|
||||
// 图片标签
|
||||
private JLabel imageLabel;
|
||||
|
||||
/**
|
||||
* AcademyThanksDialog 构造函数,初始化对话框并设置相关属性。
|
||||
*/
|
||||
public AcademyThanksDialog() {
|
||||
// 设置对话框标题
|
||||
setTitle("鸣谢");
|
||||
// 设置对话框的内容面板
|
||||
setContentPane(contentPane);
|
||||
// 设置对话框为非模态对话框
|
||||
setModal(false);
|
||||
// 设置默认按钮为确认按钮
|
||||
getRootPane().setDefaultButton(buttonOK);
|
||||
|
||||
// 为确认按钮添加事件监听器
|
||||
buttonOK.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// 点击确认按钮时执行的操作
|
||||
onOK();
|
||||
}
|
||||
});
|
||||
imageLabel.setIcon(new ImageIcon("src/com/msksbr/images/academy_logo.png"));
|
||||
|
||||
// 设置图片标签的图标
|
||||
// 设置图片标签的图标为指定路径的图片
|
||||
imageLabel.setIcon(new ImageIcon(AcademyThanksDialog.class.getResource("/com/msksbr/images/academy_logo.png")));
|
||||
|
||||
// 调整对话框大小以适应内容
|
||||
pack();
|
||||
// 设置对话框不可调整大小
|
||||
setResizable(false);
|
||||
// 设置对话框位置
|
||||
setLocation();
|
||||
// 设置对话框始终在最顶层显示
|
||||
setAlwaysOnTop(true);
|
||||
// 设置对话框可见
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 点击确认按钮时执行的操作,关闭对话框。
|
||||
*/
|
||||
private void onOK() {
|
||||
// 在此处添加您的代码
|
||||
// 关闭对话框
|
||||
dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置对话框位置,使其居中显示在屏幕上。
|
||||
*/
|
||||
public void setLocation() {
|
||||
// 设置对话框位置,使其居中显示在屏幕上
|
||||
setLocation(new ScreenSize().width / 2 - getWidth() / 2, new ScreenSize().height / 2 - getHeight() / 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,76 +10,132 @@ import java.awt.print.Book;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* BookAdder 类用于添加图书信息的对话框。
|
||||
*/
|
||||
public class BookAdder extends JDialog {
|
||||
// 内容面板
|
||||
private JPanel contentPane;
|
||||
// 确认按钮
|
||||
private JButton buttonOK;
|
||||
// 书名文本框
|
||||
private JTextField textField1;
|
||||
// 图书类型文本框
|
||||
private JTextField textField2;
|
||||
// 图书ID文本框
|
||||
private JTextField IDField;
|
||||
// ISBN文本框
|
||||
private JTextField textField4;
|
||||
// 数据库连接器
|
||||
private Connector connector;
|
||||
// 图书ID
|
||||
private int bID;
|
||||
// 书名
|
||||
private String bName;
|
||||
// 图书类型
|
||||
private String bType;
|
||||
// ISBN
|
||||
private String ISBN;
|
||||
// SQL语句
|
||||
private String sql;
|
||||
|
||||
/**
|
||||
* BookAdder 构造函数,初始化对话框并设置相关属性。
|
||||
*/
|
||||
public BookAdder() {
|
||||
|
||||
try {
|
||||
// 初始化数据库连接器
|
||||
connector = new Connector();
|
||||
// 获取最大图书ID并加1作为新图书的ID
|
||||
bID = getBookMaxID() + 1;
|
||||
} catch (ClassNotFoundException e) {
|
||||
// 抛出运行时异常
|
||||
throw new RuntimeException(e);
|
||||
} catch (SQLException e) {
|
||||
// 抛出运行时异常
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
// 为确认按钮添加事件监听器
|
||||
buttonOK.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// 点击确认按钮时执行的操作
|
||||
onOK();
|
||||
}
|
||||
});
|
||||
|
||||
// 设置图书ID文本框的文本为新图书的ID,并设置为不可编辑
|
||||
IDField.setText(String.valueOf(bID));
|
||||
IDField.setEditable(false);
|
||||
|
||||
// 设置对话框标题
|
||||
setTitle("添加图书信息");
|
||||
// 设置对话框的内容面板
|
||||
setContentPane(contentPane);
|
||||
// 设置对话框为模态对话框
|
||||
setModal(true);
|
||||
// 设置默认按钮为确认按钮
|
||||
getRootPane().setDefaultButton(buttonOK);
|
||||
|
||||
// 设置对话框不可调整大小
|
||||
setResizable(false);
|
||||
// 调整对话框大小以适应内容
|
||||
pack();
|
||||
// 设置对话框位置
|
||||
setLocation();
|
||||
// 设置对话框可见
|
||||
setVisible(true);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 点击确认按钮时执行的操作,获取用户输入的图书信息并插入到数据库中。
|
||||
*/
|
||||
private void onOK() {
|
||||
// 获取书名
|
||||
bName = textField1.getText();
|
||||
// 获取图书类型
|
||||
bType = textField2.getText();
|
||||
// 获取ISBN
|
||||
ISBN = textField4.getText();
|
||||
// 构建插入图书信息的SQL语句
|
||||
sql = "INSERT INTO books (book_name,book_id,book_type,ISBN) VALUES ('" + bName + "'," + bID + ",'" + bType + "','" + ISBN + "');";
|
||||
// 执行SQL语句
|
||||
commit2SQL();
|
||||
// 在此处添加您的代码
|
||||
// 关闭对话框
|
||||
dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取最大图书ID。
|
||||
* @return 最大图书ID
|
||||
* @throws SQLException 如果执行SQL查询时发生错误
|
||||
*/
|
||||
public int getBookMaxID() throws SQLException {
|
||||
// 执行SQL查询,获取最大图书ID
|
||||
ResultSet rs = connector.executeQuery("SELECT MAX(book_id) FROM books;");
|
||||
// 将结果集指针移动到第一行
|
||||
rs.next();
|
||||
// 返回最大图书ID
|
||||
return rs.getInt("MAX(book_id)");
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置对话框位置,使其居中显示在屏幕上。
|
||||
*/
|
||||
public void setLocation() {
|
||||
// 设置对话框位置,使其居中显示在屏幕上
|
||||
setLocation(new ScreenSize().width / 2 - getWidth() / 2, new ScreenSize().height / 2 - getHeight() / 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行SQL插入操作,将图书信息插入到数据库中。
|
||||
*/
|
||||
private void commit2SQL() {
|
||||
try {
|
||||
// 执行SQL插入操作
|
||||
connector.executeUpdate(sql);
|
||||
} catch (SQLException e) {
|
||||
// 抛出运行时异常
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,85 +9,151 @@ import java.awt.event.ActionListener;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* RentAdder 类用于添加借阅信息的对话框。
|
||||
*/
|
||||
public class RentAdder extends JDialog {
|
||||
// 内容面板
|
||||
private JPanel contentPane;
|
||||
// 确认按钮
|
||||
private JButton buttonOK;
|
||||
// 图书ID文本框
|
||||
private JTextField bIDField;
|
||||
// 学生ID文本框
|
||||
private JTextField sIDField;
|
||||
// 图书ID
|
||||
private int bID;
|
||||
// 学生ID
|
||||
private int sID;
|
||||
// 图书数据库连接器
|
||||
private Connector bConnector;
|
||||
// 学生数据库连接器
|
||||
private Connector sConnector;
|
||||
// 查询图书信息的SQL语句
|
||||
private String bookSearchSQL;
|
||||
// 查询学生信息的SQL语句
|
||||
private String studentSearchSQL;
|
||||
// 更新借阅信息的SQL语句
|
||||
private String updateSQL;
|
||||
// 查询图书信息的结果集
|
||||
private ResultSet bIDResult;
|
||||
// 查询学生信息的结果集
|
||||
private ResultSet sIDResult;
|
||||
|
||||
/**
|
||||
* RentAdder 构造函数,初始化对话框并设置相关属性。
|
||||
*/
|
||||
public RentAdder() {
|
||||
try {
|
||||
// 初始化图书数据库连接器
|
||||
bConnector = new Connector();
|
||||
// 初始化学生数据库连接器
|
||||
sConnector = new Connector();
|
||||
} catch (ClassNotFoundException e) {
|
||||
// 抛出运行时异常
|
||||
throw new RuntimeException(e);
|
||||
} catch (SQLException e) {
|
||||
// 抛出运行时异常
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
// 设置对话框的内容面板
|
||||
setContentPane(contentPane);
|
||||
// 设置对话框为模态对话框
|
||||
setModal(true);
|
||||
// 设置默认按钮为确认按钮
|
||||
getRootPane().setDefaultButton(buttonOK);
|
||||
// 设置对话框标题
|
||||
setTitle("添加借阅信息");
|
||||
|
||||
// 为确认按钮添加事件监听器
|
||||
buttonOK.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// 点击确认按钮时执行的操作
|
||||
onOK();
|
||||
}
|
||||
});
|
||||
|
||||
// 调整对话框大小以适应内容
|
||||
pack();
|
||||
// 设置对话框不可调整大小
|
||||
setResizable(false);
|
||||
// 设置对话框位置
|
||||
setLocation();
|
||||
// 设置对话框可见
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 点击确认按钮时执行的操作,获取用户输入的借阅信息并更新到数据库中。
|
||||
*/
|
||||
private void onOK() {
|
||||
// 在此处添加您的代码
|
||||
try {
|
||||
this.bID = Integer.valueOf(bIDField.getText());
|
||||
this.sID = Integer.valueOf(sIDField.getText());
|
||||
// 获取图书ID
|
||||
this.bID = Integer.parseInt(bIDField.getText());
|
||||
// 获取学生ID
|
||||
this.sID = Integer.parseInt(sIDField.getText());
|
||||
// 生成查询SQL语句
|
||||
searchSQLMaker();
|
||||
// 生成更新SQL语句
|
||||
updateSQLMaker();
|
||||
// 执行查询图书信息的SQL语句
|
||||
bIDResult = bConnector.executeQuery(bookSearchSQL);
|
||||
// 执行查询学生信息的SQL语句
|
||||
sIDResult = sConnector.executeQuery(studentSearchSQL);
|
||||
// 如果未找到图书信息,弹出错误提示框
|
||||
if (!bIDResult.next()) {
|
||||
JOptionPane.showMessageDialog(this, "未找到该书信息", "错误", JOptionPane.WARNING_MESSAGE);
|
||||
} else if (!sIDResult.next()) {
|
||||
}
|
||||
// 如果未找到学生信息,弹出错误提示框
|
||||
else if (!sIDResult.next()) {
|
||||
JOptionPane.showMessageDialog(this, "未找到学生信息", "错误", JOptionPane.WARNING_MESSAGE);
|
||||
} else {
|
||||
if (bIDResult.getInt("borrowed_by") == 0) {
|
||||
bConnector.executeUpdate(updateSQL);
|
||||
} else {
|
||||
}
|
||||
// 如果图书已借出,弹出错误提示框
|
||||
else {
|
||||
if (bIDResult.getInt("borrowed_by") != 0) {
|
||||
JOptionPane.showMessageDialog(this, "该书已借出", "错误", JOptionPane.WARNING_MESSAGE);
|
||||
}
|
||||
// 如果图书未借出,更新借阅信息
|
||||
else {
|
||||
bConnector.executeUpdate(updateSQL);
|
||||
}
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
// 如果输入的不是整数,弹出错误提示框
|
||||
JOptionPane.showMessageDialog(this, "请输入一个整数", "错误", JOptionPane.ERROR_MESSAGE);
|
||||
} catch (SQLException e) {
|
||||
// 抛出运行时异常
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
// 关闭对话框
|
||||
dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置对话框位置,使其居中显示在屏幕上。
|
||||
*/
|
||||
public void setLocation() {
|
||||
// 设置对话框位置,使其居中显示在屏幕上
|
||||
setLocation(new ScreenSize().width / 2 - getWidth() / 2, new ScreenSize().height / 2 - getHeight() / 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成查询SQL语句。
|
||||
*/
|
||||
private void searchSQLMaker() {
|
||||
// 生成查询图书信息的SQL语句
|
||||
this.bookSearchSQL = "SELECT * FROM books WHERE book_id =" + this.bID + ";";
|
||||
// 生成查询学生信息的SQL语句
|
||||
this.studentSearchSQL = "SELECT * FROM students WHERE student_id =" + this.sID + ";";
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成更新SQL语句。
|
||||
*/
|
||||
private void updateSQLMaker() {
|
||||
// 生成更新借阅信息的SQL语句
|
||||
this.updateSQL = "UPDATE books SET borrowed_by = " + this.sID + " WHERE book_id =" + this.bID + ";";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,88 +10,149 @@ import java.awt.event.ActionListener;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* StudentAdder 类用于添加学生信息的对话框。
|
||||
*/
|
||||
public class StudentAdder extends JDialog {
|
||||
// 内容面板
|
||||
private JPanel contentPane;
|
||||
// 确认按钮
|
||||
private JButton buttonOK;
|
||||
// 学生姓名文本框
|
||||
private JTextField textField1;
|
||||
// 学生ID文本框
|
||||
private JTextField IDField;
|
||||
// 学生班级文本框
|
||||
private JTextField textField3;
|
||||
// 男性单选按钮
|
||||
private JRadioButton maleRadioButton;
|
||||
// 女性单选按钮
|
||||
private JRadioButton femaleRadioButton;
|
||||
// 数据库连接器
|
||||
private Connector connector;
|
||||
// 学生姓名
|
||||
private String sName;
|
||||
// 学生ID
|
||||
private int sID;
|
||||
// 学生班级
|
||||
private String sClass;
|
||||
// 学生性别
|
||||
private String sGender;
|
||||
// 性别按钮组
|
||||
private ButtonGroup genderGroup;
|
||||
// SQL语句
|
||||
private String sql;
|
||||
|
||||
/**
|
||||
* StudentAdder 构造函数,初始化对话框并设置相关属性。
|
||||
*/
|
||||
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 {
|
||||
// 获取最大学生ID并加1作为新学生的ID
|
||||
sID = getStudentMaxID() + 1;
|
||||
// 设置学生ID文本框的文本为新学生的ID,并设置为不可编辑
|
||||
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语句
|
||||
sql = "INSERT INTO students (student_name,student_id,student_class,student_gender) VALUES ('" + sName + "'," + sID + ",'" + sClass + "','" + sGender + "');";
|
||||
// 执行SQL语句
|
||||
commit2SQL();
|
||||
// 关闭对话框
|
||||
dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行SQL插入操作,将学生信息插入到数据库中。
|
||||
*/
|
||||
private void commit2SQL() {
|
||||
try {
|
||||
// 执行SQL插入操作
|
||||
connector.executeUpdate(sql);
|
||||
} catch (SQLException e) {
|
||||
// 抛出运行时异常
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取最大学生ID。
|
||||
* @return 最大学生ID
|
||||
* @throws SQLException 如果执行SQL查询时发生错误
|
||||
*/
|
||||
public int getStudentMaxID() throws SQLException {
|
||||
// 执行SQL查询,获取最大学生ID
|
||||
ResultSet rs = connector.executeQuery("SELECT MAX(student_id) FROM students;");
|
||||
// 将结果集指针移动到第一行
|
||||
rs.next();
|
||||
// 返回最大学生ID
|
||||
return rs.getInt("MAX(student_id)");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,33 +6,65 @@ import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
/**
|
||||
* AuthorDIalog 类用于显示作者信息的对话框。
|
||||
*/
|
||||
public class AuthorDIalog extends JDialog {
|
||||
// 内容面板
|
||||
private JPanel contentPane;
|
||||
// 确认按钮
|
||||
private JButton buttonOK;
|
||||
// 图标面板
|
||||
private JPanel iconPanel;
|
||||
|
||||
/**
|
||||
* AuthorDIalog 构造函数,初始化对话框并设置相关属性。
|
||||
*/
|
||||
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"));
|
||||
authorLabel.setIcon(new ImageIcon(AuthorDIalog.class.getResource("/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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,14 +6,26 @@ import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
/**
|
||||
* MITDialog 类用于显示 MIT 许可证信息的对话框。
|
||||
*/
|
||||
public class MITDialog extends JDialog {
|
||||
// 内容面板
|
||||
private JPanel contentPane;
|
||||
// 确认按钮
|
||||
private JButton buttonOK;
|
||||
// 显示 MIT 许可证文本的文本面板
|
||||
private JTextPane MITPane;
|
||||
|
||||
/**
|
||||
* MITDialog 构造函数,初始化对话框并设置相关属性。
|
||||
*/
|
||||
public MITDialog() {
|
||||
// 设置对话框标题
|
||||
setTitle("开源信息");
|
||||
// 设置 MITPane 为不可编辑
|
||||
MITPane.setEditable(false);
|
||||
// 设置 MITPane 的文本内容为 MIT 许可证信息
|
||||
MITPane.setText("MIT License\n" +
|
||||
"\n" +
|
||||
"Copyright (c) 2024 御坂昴\n" +
|
||||
@@ -35,30 +47,48 @@ public class MITDialog extends JDialog {
|
||||
"LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n" +
|
||||
"OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n" +
|
||||
"SOFTWARE.\n");
|
||||
// 设置对话框的内容面板
|
||||
setContentPane(contentPane);
|
||||
// 设置对话框为模态对话框
|
||||
setModal(true);
|
||||
// 设置默认按钮为确认按钮
|
||||
getRootPane().setDefaultButton(buttonOK);
|
||||
// 设置对话框为非模态对话框
|
||||
setModal(false);
|
||||
|
||||
// 为确认按钮添加事件监听器
|
||||
buttonOK.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// 点击确认按钮时执行的操作
|
||||
onOK();
|
||||
}
|
||||
});
|
||||
|
||||
// 调整对话框大小以适应内容
|
||||
pack();
|
||||
// 设置对话框不可调整大小
|
||||
setResizable(false);
|
||||
// 设置对话框位置
|
||||
setLocation();
|
||||
// 设置对话框始终在最顶层显示
|
||||
setAlwaysOnTop(true);
|
||||
// 设置对话框可见
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 点击确认按钮时执行的操作,关闭对话框。
|
||||
*/
|
||||
private void onOK() {
|
||||
// 在此处添加您的代码
|
||||
// 关闭对话框
|
||||
dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置对话框位置,使其居中显示在屏幕上。
|
||||
*/
|
||||
public void setLocation() {
|
||||
// 设置对话框位置,使其居中显示在屏幕上
|
||||
setLocation(new ScreenSize().width / 2 - getWidth() / 2, new ScreenSize().height / 2 - getHeight() / 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,35 +9,61 @@ import java.awt.event.ActionListener;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Remover 类用于删除数据库中的记录。
|
||||
*/
|
||||
public class Remover extends JDialog {
|
||||
// 内容面板
|
||||
private JPanel contentPane;
|
||||
// 确认按钮
|
||||
private JButton buttonOK;
|
||||
// 标签,用于显示提示信息
|
||||
private JLabel idLable;
|
||||
// 文本框,用于输入要删除的记录的ID
|
||||
private JTextField idField;
|
||||
// 要操作的表名
|
||||
private String table;
|
||||
// 搜索SQL语句
|
||||
private String Searchsql;
|
||||
// 搜索SQL语句
|
||||
private String searchSQL;
|
||||
// 删除SQL语句
|
||||
private String deleteSQL;
|
||||
// 搜索错误信息
|
||||
private String searchErrMsg;
|
||||
// 要删除的记录的ID
|
||||
private int id;
|
||||
// 用于执行搜索操作的数据库连接器
|
||||
private Connector searchConnector;
|
||||
// 用于执行删除操作的数据库连接器
|
||||
private Connector deleteConnector;
|
||||
|
||||
/**
|
||||
* Remover 构造函数,初始化对话框并设置相关属性。
|
||||
* @param table 要操作的表名
|
||||
*/
|
||||
public Remover(String table) {
|
||||
try {
|
||||
// 初始化搜索和删除连接器
|
||||
searchConnector = new Connector();
|
||||
deleteConnector = new Connector();
|
||||
} catch (ClassNotFoundException e) {
|
||||
// 抛出运行时异常
|
||||
throw new RuntimeException(e);
|
||||
} catch (SQLException e) {
|
||||
// 抛出运行时异常
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
// 为确认按钮添加事件监听器
|
||||
buttonOK.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// 点击确认按钮时执行的操作
|
||||
onOK();
|
||||
}
|
||||
});
|
||||
// 设置要操作的表名
|
||||
this.table = table;
|
||||
// 根据表名设置对话框标题和提示信息
|
||||
if (table.equals("books")) {
|
||||
setTitle("删除图书信息");
|
||||
idLable.setText("请输入书号:");
|
||||
@@ -51,36 +77,58 @@ public class Remover extends JDialog {
|
||||
idLable.setText("请输入书号:");
|
||||
searchErrMsg = "未找到该借阅信息";
|
||||
}
|
||||
// 设置对话框的内容面板
|
||||
setContentPane(contentPane);
|
||||
// 设置对话框为模态对话框
|
||||
setModal(true);
|
||||
// 设置默认按钮为确认按钮
|
||||
getRootPane().setDefaultButton(buttonOK);
|
||||
// 调整对话框大小以适应内容
|
||||
pack();
|
||||
// 设置对话框不可调整大小
|
||||
setResizable(false);
|
||||
// 设置对话框位置
|
||||
setLocation();
|
||||
// 设置对话框可见
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 点击确认按钮时执行的操作,删除指定的记录。
|
||||
*/
|
||||
private void onOK() {
|
||||
// 在此处添加您的代码
|
||||
try {
|
||||
// 获取要删除的记录的ID
|
||||
this.id = Integer.valueOf(idField.getText());
|
||||
// 生成搜索SQL语句
|
||||
searchSQLMaker();
|
||||
// 生成删除SQL语句
|
||||
deleteSQLMaker();
|
||||
// 执行搜索操作
|
||||
ResultSet rs = searchConnector.executeQuery(searchSQL);
|
||||
// 如果找到记录,则执行删除操作
|
||||
if (rs.next()) {
|
||||
deleteConnector.executeUpdate(deleteSQL);
|
||||
} else {
|
||||
// 如果未找到记录,则显示错误信息
|
||||
JOptionPane.showMessageDialog(this, searchErrMsg, "错误", JOptionPane.WARNING_MESSAGE);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
// 如果输入的ID不是整数,则显示错误信息
|
||||
JOptionPane.showMessageDialog(this, "请输入一个整数", "错误", JOptionPane.ERROR_MESSAGE);
|
||||
} catch (SQLException e) {
|
||||
// 抛出运行时异常
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
// 关闭对话框
|
||||
dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成搜索SQL语句。
|
||||
*/
|
||||
private void searchSQLMaker() {
|
||||
// 根据表名生成搜索SQL语句
|
||||
if (table.equals("books")) {
|
||||
searchSQL = "select * from " + table + " where book_id=" + id + ";";
|
||||
} else if (table.equals("students")) {
|
||||
@@ -90,7 +138,11 @@ public class Remover extends JDialog {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成删除SQL语句。
|
||||
*/
|
||||
private void deleteSQLMaker() {
|
||||
// 根据表名生成删除SQL语句
|
||||
if (table.equals("books")) {
|
||||
deleteSQL = "delete from " + table + " where book_id=" + id + ";";
|
||||
} else if (table.equals("students")) {
|
||||
@@ -100,7 +152,11 @@ public class Remover extends JDialog {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置对话框位置,使其居中显示在屏幕上。
|
||||
*/
|
||||
public void setLocation() {
|
||||
// 设置对话框位置,使其居中显示在屏幕上
|
||||
setLocation(new ScreenSize().width / 2 - getWidth() / 2, new ScreenSize().height / 2 - getHeight() / 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,18 +11,35 @@ import java.awt.event.KeyEvent;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* SearchDIalog 类用于显示查询对话框,并根据用户输入的信息查询数据库中的记录。
|
||||
*/
|
||||
public class SearchDIalog extends JDialog {
|
||||
// 用于显示查询结果的标签
|
||||
public JLabel messageLabel;
|
||||
// 用于存储用户输入的ID
|
||||
protected int idInt;
|
||||
// 内容面板
|
||||
private JPanel contentPane;
|
||||
// 确认按钮
|
||||
private JButton buttonOK;
|
||||
// 用于输入ID的文本框
|
||||
private JTextField idFIeld;
|
||||
// 要查询的表名
|
||||
private String table;
|
||||
|
||||
/**
|
||||
* SearchDIalog 构造函数,初始化对话框并设置相关属性。
|
||||
* @param table 要查询的表名
|
||||
*/
|
||||
public SearchDIalog(String table) {
|
||||
// 设置对话框的内容面板
|
||||
setContentPane(contentPane);
|
||||
// 设置对话框为模态对话框
|
||||
setModal(true);
|
||||
// 设置默认按钮为确认按钮
|
||||
getRootPane().setDefaultButton(buttonOK);
|
||||
// 根据表名设置对话框标题和提示信息
|
||||
if (table.equals("books")) {
|
||||
this.table = "books";
|
||||
this.setTitle("查询图书信息");
|
||||
@@ -36,20 +53,31 @@ public class SearchDIalog extends JDialog {
|
||||
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();
|
||||
}
|
||||
@@ -57,16 +85,28 @@ public class SearchDIalog extends JDialog {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置对话框位置,使其居中显示在屏幕上。
|
||||
*/
|
||||
private void setLocation() {
|
||||
// 设置对话框位置,使其居中显示在屏幕上
|
||||
setLocation(new ScreenSize().width / 2 - getWidth() / 2, new ScreenSize().height / 2 - getHeight() / 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* 点击确认按钮或按下回车键时执行的操作,查询数据库并显示结果。
|
||||
*/
|
||||
private void onOK() {
|
||||
// 执行SQL查询并获取结果集
|
||||
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 = "图书信息";
|
||||
@@ -77,32 +117,53 @@ public class SearchDIalog extends JDialog {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行SQL查询并返回结果集。
|
||||
* @return 查询结果集
|
||||
*/
|
||||
private ResultSet SQLExe() {
|
||||
// 用于存储查询结果集
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
// 将用户输入的ID转换为整数
|
||||
idInt = Integer.valueOf(idFIeld.getText());
|
||||
// 创建数据库连接器
|
||||
Connector connector = new Connector();
|
||||
// 执行SQL查询并获取结果集
|
||||
rs = connector.executeQuery(SQLExeMaker(table));
|
||||
} catch (NumberFormatException e) {
|
||||
// 如果用户输入的ID不是整数,则显示错误信息
|
||||
JOptionPane.showMessageDialog(this, "请输入一个整数", "错误", JOptionPane.ERROR_MESSAGE);
|
||||
} catch (SQLException e) {
|
||||
// 抛出运行时异常
|
||||
throw new RuntimeException(e);
|
||||
} catch (ClassNotFoundException e) {
|
||||
// 抛出运行时异常
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
// 返回查询结果集
|
||||
return rs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据表名生成SQL查询语句。
|
||||
* @param table 要查询的表名
|
||||
* @return SQL查询语句
|
||||
*/
|
||||
private String SQLExeMaker(String table) {
|
||||
// 根据表名生成SQL查询语句
|
||||
if (table.equals("books")) {
|
||||
return "SELECT * FROM `books` WHERE `book_id` = " + idInt + ";";
|
||||
} else if (table.equals("students")) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="10" left="10" bottom="10" right="10"/>
|
||||
<constraints>
|
||||
<xy x="48" y="54" width="436" height="297"/>
|
||||
<xy x="48" y="54" width="573" height="297"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
@@ -40,18 +40,41 @@
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="f8413" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1">
|
||||
<grid id="f8413" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints border-constraint="South"/>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="48047" class="javax.swing.JLabel">
|
||||
<constraints/>
|
||||
<properties>
|
||||
<font name="PingFang SC" size="14"/>
|
||||
<text value="https://gitee.com/msksbr/system-homework-in-the-library"/>
|
||||
</properties>
|
||||
</component>
|
||||
<grid id="d3052" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1">
|
||||
<constraints border-constraint="South"/>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="48047" class="javax.swing.JLabel">
|
||||
<constraints/>
|
||||
<properties>
|
||||
<font name="PingFang SC" size="14"/>
|
||||
<text value="https://gitee.com/msksbr/system-homework-in-the-library"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="20d87" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints border-constraint="North"/>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="5423a" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="本软件完全免费,如果您从任何渠道购买到此软件及其源码,请联系作者:3141661556@qq.com"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="bae5e" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
|
||||
@@ -5,40 +5,85 @@ import com.msksbr.LoginFrm.ScreenSize;
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* aboutDIalog 类用于显示关于图书管理系统的对话框。
|
||||
*/
|
||||
public class aboutDIalog extends JDialog {
|
||||
// 内容面板
|
||||
private JPanel contentPane;
|
||||
// 确认按钮
|
||||
private JButton buttonOK;
|
||||
// 图标面板
|
||||
private JPanel iconPanel;
|
||||
|
||||
/**
|
||||
* aboutDIalog 构造函数,初始化对话框并设置相关属性。
|
||||
*/
|
||||
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"));
|
||||
// 使用类加载器获取资源的URL
|
||||
URL iconUrl = getClass().getResource("/com/msksbr/images/logo_128.png");
|
||||
if (iconUrl != null) {
|
||||
// 创建ImageIcon对象
|
||||
iconLabel.setIcon(new ImageIcon(iconUrl));
|
||||
} else {
|
||||
// 如果资源未找到,记录错误或显示默认图标
|
||||
System.err.println("图标资源未找到: /com/msksbr/images/logo_128.png");
|
||||
// 可以在这里设置一个默认图标
|
||||
// iconLabel.setIcon(new ImageIcon("path/to/default/icon.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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,36 +6,67 @@ import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
/**
|
||||
* showMessae 类用于显示一个包含指定消息的模态对话框。
|
||||
*/
|
||||
public class showMessae extends JDialog {
|
||||
// 内容面板
|
||||
private JPanel contentPane;
|
||||
// 确认按钮
|
||||
private JButton buttonOK;
|
||||
// 用于显示消息的文本面板
|
||||
private JTextPane textPane1;
|
||||
|
||||
/**
|
||||
* showMessae 构造函数,初始化对话框并设置相关属性。
|
||||
* @param message 要显示的消息内容
|
||||
* @param title 对话框的标题
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,23 +2,56 @@ package com.msksbr.SQL;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
/**
|
||||
* 数据库连接类,用于连接到MySQL数据库并执行SQL查询和更新操作。
|
||||
*/
|
||||
public class Connector {
|
||||
// 数据库连接对象
|
||||
private Connection conn;
|
||||
// SQL语句执行对象
|
||||
private Statement stmt;
|
||||
private String url = "jdbc:mysql://localhost:3306/book";
|
||||
// 数据库连接URL
|
||||
private String url = "jdbc:mysql://192.168.154.139:3306/book";
|
||||
// 数据库用户名
|
||||
private String user = "root";
|
||||
|
||||
/**
|
||||
* 构造方法,初始化数据库连接。
|
||||
*
|
||||
* @throws ClassNotFoundException 如果找不到MySQL驱动类。
|
||||
* @throws SQLException 如果数据库连接失败。
|
||||
*/
|
||||
public Connector() throws ClassNotFoundException, SQLException {
|
||||
// 加载MySQL驱动类
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
// 获取数据库连接
|
||||
conn = DriverManager.getConnection(url, user, new PassWord().passWord);
|
||||
// 创建SQL语句执行对象
|
||||
stmt = conn.createStatement();
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行SQL查询操作。
|
||||
*
|
||||
* @param query 要执行的SQL查询语句。
|
||||
* @return 查询结果集。
|
||||
* @throws SQLException 如果查询执行失败。
|
||||
*/
|
||||
public ResultSet executeQuery(String query) throws SQLException {
|
||||
// 执行SQL查询并返回结果集
|
||||
return stmt.executeQuery(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行SQL更新操作。
|
||||
*
|
||||
* @param query 要执行的SQL更新语句。
|
||||
* @return 受影响的行数。
|
||||
* @throws SQLException 如果更新执行失败。
|
||||
*/
|
||||
public int executeUpdate(String query) throws SQLException {
|
||||
// 执行SQL更新并返回受影响的行数
|
||||
return stmt.executeUpdate(query);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,36 +6,68 @@ import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
/**
|
||||
* EasterEgg 类表示一个彩蛋对话框,用于显示特定的图像。
|
||||
*/
|
||||
public class EasterEgg extends JDialog {
|
||||
// 对话框的内容面板
|
||||
private JPanel contentPane;
|
||||
// 确认按钮
|
||||
private JButton buttonOK;
|
||||
// 用于显示图像的标签
|
||||
private JLabel imageLable;
|
||||
|
||||
/**
|
||||
* 构造函数,初始化 EasterEgg 对话框。
|
||||
*/
|
||||
public EasterEgg() {
|
||||
// 设置对话框的标题
|
||||
setTitle("Easter Egg!");
|
||||
// 设置对话框的内容面板
|
||||
setContentPane(contentPane);
|
||||
// 设置对话框为模态对话框
|
||||
setModal(true);
|
||||
// 设置默认按钮为 buttonOK
|
||||
getRootPane().setDefaultButton(buttonOK);
|
||||
imageLable.setIcon(new ImageIcon("src/com/msksbr/images/BuzzBeans.png"));
|
||||
|
||||
// 设置 imageLable 的图标为指定路径的图像
|
||||
imageLable.setIcon(new ImageIcon(EasterEgg.class.getResource("/com/msksbr/images/BuzzBeans.png")));
|
||||
// 为 buttonOK 添加动作监听器
|
||||
buttonOK.addActionListener(new ActionListener() {
|
||||
/**
|
||||
* 当按钮被点击时调用的方法。
|
||||
*
|
||||
* @param e 动作事件
|
||||
*/
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// 调用 onOK 方法
|
||||
onOK();
|
||||
}
|
||||
});
|
||||
|
||||
// 调整对话框的大小以适应其内容
|
||||
pack();
|
||||
// 设置对话框不可调整大小
|
||||
setResizable(false);
|
||||
// 设置对话框的位置
|
||||
setLocation();
|
||||
// 设置对话框可见
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当用户点击确认按钮时调用的方法。
|
||||
*/
|
||||
private void onOK() {
|
||||
// 在此处添加您的代码
|
||||
// 关闭对话框
|
||||
dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置对话框的位置为屏幕中心。
|
||||
*/
|
||||
public void setLocation() {
|
||||
// 设置对话框的位置为屏幕中心
|
||||
setLocation(new ScreenSize().width / 2 - getWidth() / 2, new ScreenSize().height / 2 - getHeight() / 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="AdditionalModuleElements">
|
||||
<content url="file://$MODULE_DIR$" dumb="true">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
</component>
|
||||
</module>
|
||||
Reference in New Issue
Block a user