添加注释
This commit is contained in:
@@ -10,52 +10,88 @@ import java.awt.event.*;
|
|||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主窗口类,继承自JFrame,用于显示图书管理系统的主界面
|
||||||
|
*/
|
||||||
public class MainFrm extends JFrame {
|
public class MainFrm extends JFrame {
|
||||||
|
// 数据库连接器对象,用于与数据库进行交互
|
||||||
private Connector connector;
|
private Connector connector;
|
||||||
|
// 主面板,用于容纳其他组件
|
||||||
private JPanel panel1;
|
private JPanel panel1;
|
||||||
|
// 表格面板,用于显示数据表格(当前未使用)
|
||||||
private JPanel tablePanel;
|
private JPanel tablePanel;
|
||||||
|
// 底部面板,用于显示统计信息
|
||||||
private JPanel bottomPanel;
|
private JPanel bottomPanel;
|
||||||
|
// 背景标签,用于显示背景图片
|
||||||
private JLabel backLabel;
|
private JLabel backLabel;
|
||||||
|
// 统计信息标签,用于显示图书、学生和借阅记录的数量
|
||||||
private JLabel countMessage = new JLabel();
|
private JLabel countMessage = new JLabel();
|
||||||
|
// 菜单栏对象,用于显示菜单选项
|
||||||
private MenuBar menuBar;
|
private MenuBar menuBar;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造方法,初始化主窗口并设置相关属性
|
||||||
|
* @throws SQLException 如果数据库操作失败抛出此异常
|
||||||
|
* @throws ClassNotFoundException 如果找不到数据库驱动类抛出此异常
|
||||||
|
*/
|
||||||
public MainFrm() throws SQLException, ClassNotFoundException {
|
public MainFrm() throws SQLException, ClassNotFoundException {
|
||||||
|
// 设置窗口图标
|
||||||
setIconImage(new ImageIcon("src/com/msksbr/images/mainicon.png").getImage());
|
setIconImage(new ImageIcon("src/com/msksbr/images/mainicon.png").getImage());
|
||||||
|
// 初始化数据库连接器
|
||||||
connector = new Connector();
|
connector = new Connector();
|
||||||
|
// 设置窗口标题
|
||||||
setTitle("图书管理系统");
|
setTitle("图书管理系统");
|
||||||
|
// 设置窗口内容面板
|
||||||
setContentPane(panel1);
|
setContentPane(panel1);
|
||||||
|
// 调整窗口大小以适应内容
|
||||||
pack();
|
pack();
|
||||||
|
|
||||||
|
// 初始化菜单栏
|
||||||
menuBar = new MenuBar();
|
menuBar = new MenuBar();
|
||||||
|
// 设置窗口的菜单栏
|
||||||
|
|
||||||
setJMenuBar(menuBar);
|
setJMenuBar(menuBar);
|
||||||
|
// 设置窗口关闭操作
|
||||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||||
|
// 设置窗口大小
|
||||||
setSize(960, 720);
|
setSize(960, 720);
|
||||||
|
|
||||||
|
// 获取并设置统计信息
|
||||||
String countData = "本馆共藏书" + getCount("books") + "本,共记录学生信息" + getCount("students") + "条,已借阅" + getCount("rents") + "本书,人均借阅" + (double) getCount("rents") / getCount("students") + "本";
|
String countData = "本馆共藏书" + getCount("books") + "本,共记录学生信息" + getCount("students") + "条,已借阅" + getCount("rents") + "本书,人均借阅" + (double) getCount("rents") / getCount("students") + "本";
|
||||||
countMessage.setText(countData);
|
countMessage.setText(countData);
|
||||||
|
// 将统计信息标签添加到底部面板
|
||||||
bottomPanel.add(countMessage);
|
bottomPanel.add(countMessage);
|
||||||
|
// 创建并设置背景图片
|
||||||
ImageIcon imageIcon = new ImageIcon("src/com/msksbr/images/backGround.png");
|
ImageIcon imageIcon = new ImageIcon("src/com/msksbr/images/backGround.png");
|
||||||
imageIcon.setImage(imageIcon.getImage().getScaledInstance(250, 250, 0));
|
imageIcon.setImage(imageIcon.getImage().getScaledInstance(250, 250, 0));
|
||||||
|
// 设置背景标签的图标
|
||||||
backLabel.setIcon(imageIcon);
|
backLabel.setIcon(imageIcon);
|
||||||
|
|
||||||
|
// 设置窗口的最小尺寸
|
||||||
setMinimumSize(new Dimension(960, 720));
|
setMinimumSize(new Dimension(960, 720));
|
||||||
|
|
||||||
|
// 设置窗口位置
|
||||||
setLocation();
|
setLocation();
|
||||||
|
// 初始化对话框
|
||||||
initDialogs();
|
initDialogs();
|
||||||
|
// 设置窗口可见
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置窗口位置,使其居中显示在屏幕上
|
||||||
|
*/
|
||||||
private void setLocation() {
|
private void setLocation() {
|
||||||
|
// 创建一个 ScreenSize 对象,用于获取屏幕尺寸
|
||||||
ScreenSize screenSize = new ScreenSize();
|
ScreenSize screenSize = new ScreenSize();
|
||||||
|
// 设置窗口位置,使其居中显示在屏幕上
|
||||||
setLocation(screenSize.width / 2 - getWidth() / 2, screenSize.height / 2 - getHeight() / 2);
|
setLocation(screenSize.width / 2 - getWidth() / 2, screenSize.height / 2 - getHeight() / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化对话框,为退出菜单项添加事件监听器
|
||||||
|
*/
|
||||||
private void initDialogs() {
|
private void initDialogs() {
|
||||||
|
// 为退出菜单项添加事件监听器,当点击退出菜单项时,调用 System.exit(0) 方法退出程序
|
||||||
menuBar.exitItem.addActionListener(
|
menuBar.exitItem.addActionListener(
|
||||||
new ActionListener() {
|
new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
@@ -65,9 +101,18 @@ public class MainFrm extends JFrame {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取指定表中的记录数
|
||||||
|
* @param table 表名
|
||||||
|
* @return 表中的记录数
|
||||||
|
* @throws SQLException 如果执行 SQL 查询时发生错误
|
||||||
|
*/
|
||||||
private int getCount(String table) throws SQLException {
|
private int getCount(String table) throws SQLException {
|
||||||
|
// 执行 SQL 查询,获取指定表中的记录数
|
||||||
ResultSet rs = connector.executeQuery("SELECT COUNT(*) FROM " + table + ";");
|
ResultSet rs = connector.executeQuery("SELECT COUNT(*) FROM " + table + ";");
|
||||||
|
// 将结果集指针移动到第一行
|
||||||
rs.next();
|
rs.next();
|
||||||
|
// 返回查询结果中的记录数
|
||||||
return rs.getInt("COUNT(*)");
|
return rs.getInt("COUNT(*)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,114 +9,161 @@ import javax.swing.*;
|
|||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主窗口菜单栏类,继承自JMenuBar,用于创建和管理菜单栏及其菜单项
|
||||||
|
*/
|
||||||
public class MenuBar extends JMenuBar {
|
public class MenuBar extends JMenuBar {
|
||||||
|
// 退出菜单项,用于退出应用程序
|
||||||
public JMenuItem exitItem;
|
public JMenuItem exitItem;
|
||||||
|
// 关于对话框,用于显示关于软件的信息
|
||||||
protected com.msksbr.MainFrm.MenuItemDiaog.aboutDIalog aboutDIalog;
|
protected com.msksbr.MainFrm.MenuItemDiaog.aboutDIalog aboutDIalog;
|
||||||
|
// 作者对话框,用于显示软件作者的信息
|
||||||
protected AuthorDIalog authorDIalog;
|
protected AuthorDIalog authorDIalog;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造方法,初始化菜单栏并添加菜单项
|
||||||
|
*/
|
||||||
public MenuBar() {
|
public MenuBar() {
|
||||||
// “文件“菜单
|
// “文件“菜单
|
||||||
JMenu fileMenu = new JMenu("文件");
|
JMenu fileMenu = new JMenu("文件");
|
||||||
|
// 创建退出菜单项
|
||||||
exitItem = new JMenuItem("退出");
|
exitItem = new JMenuItem("退出");
|
||||||
|
// 将退出菜单项添加到文件菜单
|
||||||
fileMenu.add(exitItem);
|
fileMenu.add(exitItem);
|
||||||
|
|
||||||
// ”查询“菜单
|
// ”查询“菜单
|
||||||
JMenu searchMenu = new JMenu("查询");
|
JMenu searchMenu = new JMenu("查询");
|
||||||
|
// 创建查询图书信息菜单项
|
||||||
JMenuItem bookSearch = new JMenuItem("查询图书信息");
|
JMenuItem bookSearch = new JMenuItem("查询图书信息");
|
||||||
|
// 为查询图书信息菜单项添加事件监听器,当点击时弹出图书信息查询对话框
|
||||||
bookSearch.addActionListener(new ActionListener() {
|
bookSearch.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
new SearchDIalog("books");
|
new SearchDIalog("books");
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
);
|
// 创建查询学生信息菜单项
|
||||||
JMenuItem studentSearch = new JMenuItem("查询学生信息");
|
JMenuItem studentSearch = new JMenuItem("查询学生信息");
|
||||||
|
// 为查询学生信息菜单项添加事件监听器,当点击时弹出学生信息查询对话框
|
||||||
studentSearch.addActionListener(new ActionListener() {
|
studentSearch.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
new SearchDIalog("students");
|
new SearchDIalog("students");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// 创建查询借阅信息菜单项
|
||||||
JMenuItem rentSearch = new JMenuItem("查询借阅信息");
|
JMenuItem rentSearch = new JMenuItem("查询借阅信息");
|
||||||
|
// 为查询借阅信息菜单项添加事件监听器,当点击时弹出借阅信息查询对话框
|
||||||
rentSearch.addActionListener(new ActionListener() {
|
rentSearch.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
new SearchDIalog("rents");
|
new SearchDIalog("rents");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// 将查询图书信息菜单项添加到查询菜单
|
||||||
searchMenu.add(bookSearch);
|
searchMenu.add(bookSearch);
|
||||||
|
// 将查询学生信息菜单项添加到查询菜单
|
||||||
searchMenu.add(studentSearch);
|
searchMenu.add(studentSearch);
|
||||||
|
// 将查询借阅信息菜单项添加到查询菜单
|
||||||
searchMenu.add(rentSearch);
|
searchMenu.add(rentSearch);
|
||||||
|
|
||||||
// ”添加“菜单
|
// ”添加“菜单
|
||||||
JMenu addMenu = new JMenu("添加");
|
JMenu addMenu = new JMenu("添加");
|
||||||
|
// 创建添加图书信息菜单项
|
||||||
JMenuItem bookAdd = new JMenuItem("添加图书信息");
|
JMenuItem bookAdd = new JMenuItem("添加图书信息");
|
||||||
|
// 为添加图书信息菜单项添加事件监听器,当点击时弹出图书信息添加对话框
|
||||||
bookAdd.addActionListener(new ActionListener() {
|
bookAdd.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
new BookAdder();
|
new BookAdder();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// 创建添加学生信息菜单项
|
||||||
JMenuItem studentAdd = new JMenuItem("添加学生信息");
|
JMenuItem studentAdd = new JMenuItem("添加学生信息");
|
||||||
|
// 为添加学生信息菜单项添加事件监听器,当点击时弹出学生信息添加对话框
|
||||||
studentAdd.addActionListener(new ActionListener() {
|
studentAdd.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
new StudentAdder();
|
new StudentAdder();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// 创建添加借阅信息菜单项
|
||||||
JMenuItem rentAdd = new JMenuItem("添加借阅信息");
|
JMenuItem rentAdd = new JMenuItem("添加借阅信息");
|
||||||
|
// 为添加借阅信息菜单项添加事件监听器,当点击时弹出借阅信息添加对话框
|
||||||
rentAdd.addActionListener(new ActionListener() {
|
rentAdd.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
new RentAdder();
|
new RentAdder();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// 将添加图书信息菜单项添加到添加菜单
|
||||||
addMenu.add(bookAdd);
|
addMenu.add(bookAdd);
|
||||||
|
// 将添加学生信息菜单项添加到添加菜单
|
||||||
addMenu.add(studentAdd);
|
addMenu.add(studentAdd);
|
||||||
|
// 将添加借阅信息菜单项添加到添加菜单
|
||||||
addMenu.add(rentAdd);
|
addMenu.add(rentAdd);
|
||||||
|
|
||||||
// ”删除“菜单
|
// ”删除“菜单
|
||||||
JMenu removeMenu = new JMenu("删除");
|
JMenu removeMenu = new JMenu("删除");
|
||||||
|
// 创建删除图书信息菜单项
|
||||||
JMenuItem bookRemove = new JMenuItem("删除图书信息");
|
JMenuItem bookRemove = new JMenuItem("删除图书信息");
|
||||||
|
// 为删除图书信息菜单项添加事件监听器,当点击时弹出图书信息删除对话框
|
||||||
bookRemove.addActionListener(new ActionListener() {
|
bookRemove.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
new Remover("books");
|
new Remover("books");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// 创建删除学生信息菜单项
|
||||||
JMenuItem studentRemove = new JMenuItem("删除学生信息");
|
JMenuItem studentRemove = new JMenuItem("删除学生信息");
|
||||||
|
// 为删除学生信息菜单项添加事件监听器,当点击时弹出学生信息删除对话框
|
||||||
studentRemove.addActionListener(new ActionListener() {
|
studentRemove.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
new Remover("students");
|
new Remover("students");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// 创建删除借阅信息菜单项
|
||||||
JMenuItem rentRemove = new JMenuItem("删除借阅信息");
|
JMenuItem rentRemove = new JMenuItem("删除借阅信息");
|
||||||
|
// 为删除借阅信息菜单项添加事件监听器,当点击时弹出借阅信息删除对话框
|
||||||
rentRemove.addActionListener(new ActionListener() {
|
rentRemove.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
new Remover("rents");
|
new Remover("rents");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// 将删除图书信息菜单项添加到删除菜单
|
||||||
removeMenu.add(bookRemove);
|
removeMenu.add(bookRemove);
|
||||||
|
// 将删除学生信息菜单项添加到删除菜单
|
||||||
removeMenu.add(studentRemove);
|
removeMenu.add(studentRemove);
|
||||||
|
// 将删除借阅信息菜单项添加到删除菜单
|
||||||
removeMenu.add(rentRemove);
|
removeMenu.add(rentRemove);
|
||||||
|
|
||||||
// ”关于“菜单
|
// ”关于“菜单
|
||||||
JMenu aboutMenu = new JMenu("关于");
|
JMenu aboutMenu = new JMenu("关于");
|
||||||
|
// 创建关于软件菜单项
|
||||||
JMenuItem about = new JMenuItem("关于软件");
|
JMenuItem about = new JMenuItem("关于软件");
|
||||||
|
// 创建关于软件的对话框
|
||||||
aboutDIalog = new aboutDIalog();
|
aboutDIalog = new aboutDIalog();
|
||||||
|
// 为关于软件菜单项添加事件监听器,当点击时显示关于软件的对话框
|
||||||
about.addActionListener(new ActionListener() {
|
about.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
aboutDIalog.setVisible(true);
|
aboutDIalog.setVisible(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// 创建作者菜单项
|
||||||
JMenuItem author = new JMenuItem("作者");
|
JMenuItem author = new JMenuItem("作者");
|
||||||
|
// 创建软件作者的对话框
|
||||||
authorDIalog = new AuthorDIalog();
|
authorDIalog = new AuthorDIalog();
|
||||||
|
// 为作者菜单项添加事件监听器,当点击时显示软件作者的对话框
|
||||||
author.addActionListener(new ActionListener() {
|
author.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
authorDIalog.setVisible(true);
|
authorDIalog.setVisible(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// 创建MIT许可证菜单项
|
||||||
JMenuItem MITLicense = new JMenuItem("MIT许可证");
|
JMenuItem MITLicense = new JMenuItem("MIT许可证");
|
||||||
|
// 为MIT许可证菜单项添加事件监听器,当点击时显示MIT许可证的对话框
|
||||||
MITLicense.addActionListener(new ActionListener() {
|
MITLicense.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
new MITDialog();
|
new MITDialog();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// 创建鸣谢菜单项
|
||||||
JMenuItem thanksItem = new JMenuItem("鸣谢");
|
JMenuItem thanksItem = new JMenuItem("鸣谢");
|
||||||
|
// 为鸣谢菜单项添加事件监听器,当点击时显示鸣谢信息的对话框
|
||||||
thanksItem.addActionListener(
|
thanksItem.addActionListener(
|
||||||
new ActionListener() {
|
new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
@@ -124,16 +171,25 @@ public class MenuBar extends JMenuBar {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
// 将关于软件菜单项添加到关于菜单
|
||||||
aboutMenu.add(about);
|
aboutMenu.add(about);
|
||||||
|
// 将作者菜单项添加到关于菜单
|
||||||
aboutMenu.add(author);
|
aboutMenu.add(author);
|
||||||
|
// 将MIT许可证菜单项添加到关于菜单
|
||||||
aboutMenu.add(MITLicense);
|
aboutMenu.add(MITLicense);
|
||||||
|
// 将鸣谢菜单项添加到关于菜单
|
||||||
aboutMenu.add(thanksItem);
|
aboutMenu.add(thanksItem);
|
||||||
|
|
||||||
//将菜单加入菜单栏
|
//将菜单加入菜单栏
|
||||||
|
// 将文件菜单添加到菜单栏
|
||||||
add(fileMenu);
|
add(fileMenu);
|
||||||
|
// 将查询菜单添加到菜单栏
|
||||||
add(searchMenu);
|
add(searchMenu);
|
||||||
|
// 将添加菜单添加到菜单栏
|
||||||
add(addMenu);
|
add(addMenu);
|
||||||
|
// 将删除菜单添加到菜单栏
|
||||||
add(removeMenu);
|
add(removeMenu);
|
||||||
|
// 将关于菜单添加到菜单栏
|
||||||
add(aboutMenu);
|
add(aboutMenu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,36 +6,65 @@ import javax.swing.*;
|
|||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AcademyThanksDialog 类用于显示鸣谢信息的对话框。
|
||||||
|
*/
|
||||||
public class AcademyThanksDialog extends JDialog {
|
public class AcademyThanksDialog extends JDialog {
|
||||||
|
// 内容面板
|
||||||
private JPanel contentPane;
|
private JPanel contentPane;
|
||||||
|
// 确认按钮
|
||||||
private JButton buttonOK;
|
private JButton buttonOK;
|
||||||
|
// 图片标签
|
||||||
private JLabel imageLabel;
|
private JLabel imageLabel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AcademyThanksDialog 构造函数,初始化对话框并设置相关属性。
|
||||||
|
*/
|
||||||
public AcademyThanksDialog() {
|
public AcademyThanksDialog() {
|
||||||
|
// 设置对话框标题
|
||||||
setTitle("鸣谢");
|
setTitle("鸣谢");
|
||||||
|
// 设置对话框的内容面板
|
||||||
setContentPane(contentPane);
|
setContentPane(contentPane);
|
||||||
|
// 设置对话框为非模态对话框
|
||||||
setModal(false);
|
setModal(false);
|
||||||
|
// 设置默认按钮为确认按钮
|
||||||
getRootPane().setDefaultButton(buttonOK);
|
getRootPane().setDefaultButton(buttonOK);
|
||||||
|
|
||||||
|
// 为确认按钮添加事件监听器
|
||||||
buttonOK.addActionListener(new ActionListener() {
|
buttonOK.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
// 点击确认按钮时执行的操作
|
||||||
onOK();
|
onOK();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 设置图片标签的图标
|
||||||
imageLabel.setIcon(new ImageIcon("src/com/msksbr/images/academy_logo.png"));
|
imageLabel.setIcon(new ImageIcon("src/com/msksbr/images/academy_logo.png"));
|
||||||
|
// 调整对话框大小以适应内容
|
||||||
pack();
|
pack();
|
||||||
|
// 设置对话框不可调整大小
|
||||||
setResizable(false);
|
setResizable(false);
|
||||||
|
// 设置对话框位置
|
||||||
setLocation();
|
setLocation();
|
||||||
|
// 设置对话框始终在最顶层显示
|
||||||
setAlwaysOnTop(true);
|
setAlwaysOnTop(true);
|
||||||
|
// 设置对话框可见
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 点击确认按钮时执行的操作,关闭对话框。
|
||||||
|
*/
|
||||||
private void onOK() {
|
private void onOK() {
|
||||||
// 在此处添加您的代码
|
// 关闭对话框
|
||||||
dispose();
|
dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置对话框位置,使其居中显示在屏幕上。
|
||||||
|
*/
|
||||||
public void setLocation() {
|
public void setLocation() {
|
||||||
|
// 设置对话框位置,使其居中显示在屏幕上
|
||||||
setLocation(new ScreenSize().width / 2 - getWidth() / 2, new ScreenSize().height / 2 - getHeight() / 2);
|
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.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BookAdder 类用于添加图书信息的对话框。
|
||||||
|
*/
|
||||||
public class BookAdder extends JDialog {
|
public class BookAdder extends JDialog {
|
||||||
|
// 内容面板
|
||||||
private JPanel contentPane;
|
private JPanel contentPane;
|
||||||
|
// 确认按钮
|
||||||
private JButton buttonOK;
|
private JButton buttonOK;
|
||||||
|
// 书名文本框
|
||||||
private JTextField textField1;
|
private JTextField textField1;
|
||||||
|
// 图书类型文本框
|
||||||
private JTextField textField2;
|
private JTextField textField2;
|
||||||
|
// 图书ID文本框
|
||||||
private JTextField IDField;
|
private JTextField IDField;
|
||||||
|
// ISBN文本框
|
||||||
private JTextField textField4;
|
private JTextField textField4;
|
||||||
|
// 数据库连接器
|
||||||
private Connector connector;
|
private Connector connector;
|
||||||
|
// 图书ID
|
||||||
private int bID;
|
private int bID;
|
||||||
|
// 书名
|
||||||
private String bName;
|
private String bName;
|
||||||
|
// 图书类型
|
||||||
private String bType;
|
private String bType;
|
||||||
|
// ISBN
|
||||||
private String ISBN;
|
private String ISBN;
|
||||||
|
// SQL语句
|
||||||
private String sql;
|
private String sql;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BookAdder 构造函数,初始化对话框并设置相关属性。
|
||||||
|
*/
|
||||||
public BookAdder() {
|
public BookAdder() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// 初始化数据库连接器
|
||||||
connector = new Connector();
|
connector = new Connector();
|
||||||
|
// 获取最大图书ID并加1作为新图书的ID
|
||||||
bID = getBookMaxID() + 1;
|
bID = getBookMaxID() + 1;
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
|
// 抛出运行时异常
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
// 抛出运行时异常
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 为确认按钮添加事件监听器
|
||||||
buttonOK.addActionListener(new ActionListener() {
|
buttonOK.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
// 点击确认按钮时执行的操作
|
||||||
onOK();
|
onOK();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 设置图书ID文本框的文本为新图书的ID,并设置为不可编辑
|
||||||
IDField.setText(String.valueOf(bID));
|
IDField.setText(String.valueOf(bID));
|
||||||
IDField.setEditable(false);
|
IDField.setEditable(false);
|
||||||
|
|
||||||
|
// 设置对话框标题
|
||||||
setTitle("添加图书信息");
|
setTitle("添加图书信息");
|
||||||
|
// 设置对话框的内容面板
|
||||||
setContentPane(contentPane);
|
setContentPane(contentPane);
|
||||||
|
// 设置对话框为模态对话框
|
||||||
setModal(true);
|
setModal(true);
|
||||||
|
// 设置默认按钮为确认按钮
|
||||||
getRootPane().setDefaultButton(buttonOK);
|
getRootPane().setDefaultButton(buttonOK);
|
||||||
|
|
||||||
|
// 设置对话框不可调整大小
|
||||||
setResizable(false);
|
setResizable(false);
|
||||||
|
// 调整对话框大小以适应内容
|
||||||
pack();
|
pack();
|
||||||
|
// 设置对话框位置
|
||||||
setLocation();
|
setLocation();
|
||||||
|
// 设置对话框可见
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 点击确认按钮时执行的操作,获取用户输入的图书信息并插入到数据库中。
|
||||||
|
*/
|
||||||
private void onOK() {
|
private void onOK() {
|
||||||
|
// 获取书名
|
||||||
bName = textField1.getText();
|
bName = textField1.getText();
|
||||||
|
// 获取图书类型
|
||||||
bType = textField2.getText();
|
bType = textField2.getText();
|
||||||
|
// 获取ISBN
|
||||||
ISBN = textField4.getText();
|
ISBN = textField4.getText();
|
||||||
|
// 构建插入图书信息的SQL语句
|
||||||
sql = "INSERT INTO books (book_name,book_id,book_type,ISBN) VALUES ('" + bName + "'," + bID + ",'" + bType + "','" + ISBN + "');";
|
sql = "INSERT INTO books (book_name,book_id,book_type,ISBN) VALUES ('" + bName + "'," + bID + ",'" + bType + "','" + ISBN + "');";
|
||||||
|
// 执行SQL语句
|
||||||
commit2SQL();
|
commit2SQL();
|
||||||
// 在此处添加您的代码
|
// 关闭对话框
|
||||||
dispose();
|
dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取最大图书ID。
|
||||||
|
* @return 最大图书ID
|
||||||
|
* @throws SQLException 如果执行SQL查询时发生错误
|
||||||
|
*/
|
||||||
public int getBookMaxID() throws SQLException {
|
public int getBookMaxID() throws SQLException {
|
||||||
|
// 执行SQL查询,获取最大图书ID
|
||||||
ResultSet rs = connector.executeQuery("SELECT MAX(book_id) FROM books;");
|
ResultSet rs = connector.executeQuery("SELECT MAX(book_id) FROM books;");
|
||||||
|
// 将结果集指针移动到第一行
|
||||||
rs.next();
|
rs.next();
|
||||||
|
// 返回最大图书ID
|
||||||
return rs.getInt("MAX(book_id)");
|
return rs.getInt("MAX(book_id)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置对话框位置,使其居中显示在屏幕上。
|
||||||
|
*/
|
||||||
public void setLocation() {
|
public void setLocation() {
|
||||||
|
// 设置对话框位置,使其居中显示在屏幕上
|
||||||
setLocation(new ScreenSize().width / 2 - getWidth() / 2, new ScreenSize().height / 2 - getHeight() / 2);
|
setLocation(new ScreenSize().width / 2 - getWidth() / 2, new ScreenSize().height / 2 - getHeight() / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行SQL插入操作,将图书信息插入到数据库中。
|
||||||
|
*/
|
||||||
private void commit2SQL() {
|
private void commit2SQL() {
|
||||||
try {
|
try {
|
||||||
|
// 执行SQL插入操作
|
||||||
connector.executeUpdate(sql);
|
connector.executeUpdate(sql);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
// 抛出运行时异常
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,85 +9,151 @@ import java.awt.event.ActionListener;
|
|||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RentAdder 类用于添加借阅信息的对话框。
|
||||||
|
*/
|
||||||
public class RentAdder extends JDialog {
|
public class RentAdder extends JDialog {
|
||||||
|
// 内容面板
|
||||||
private JPanel contentPane;
|
private JPanel contentPane;
|
||||||
|
// 确认按钮
|
||||||
private JButton buttonOK;
|
private JButton buttonOK;
|
||||||
|
// 图书ID文本框
|
||||||
private JTextField bIDField;
|
private JTextField bIDField;
|
||||||
|
// 学生ID文本框
|
||||||
private JTextField sIDField;
|
private JTextField sIDField;
|
||||||
|
// 图书ID
|
||||||
private int bID;
|
private int bID;
|
||||||
|
// 学生ID
|
||||||
private int sID;
|
private int sID;
|
||||||
|
// 图书数据库连接器
|
||||||
private Connector bConnector;
|
private Connector bConnector;
|
||||||
|
// 学生数据库连接器
|
||||||
private Connector sConnector;
|
private Connector sConnector;
|
||||||
|
// 查询图书信息的SQL语句
|
||||||
private String bookSearchSQL;
|
private String bookSearchSQL;
|
||||||
|
// 查询学生信息的SQL语句
|
||||||
private String studentSearchSQL;
|
private String studentSearchSQL;
|
||||||
|
// 更新借阅信息的SQL语句
|
||||||
private String updateSQL;
|
private String updateSQL;
|
||||||
|
// 查询图书信息的结果集
|
||||||
private ResultSet bIDResult;
|
private ResultSet bIDResult;
|
||||||
|
// 查询学生信息的结果集
|
||||||
private ResultSet sIDResult;
|
private ResultSet sIDResult;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RentAdder 构造函数,初始化对话框并设置相关属性。
|
||||||
|
*/
|
||||||
public RentAdder() {
|
public RentAdder() {
|
||||||
try {
|
try {
|
||||||
|
// 初始化图书数据库连接器
|
||||||
bConnector = new Connector();
|
bConnector = new Connector();
|
||||||
|
// 初始化学生数据库连接器
|
||||||
sConnector = new Connector();
|
sConnector = new Connector();
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
|
// 抛出运行时异常
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
// 抛出运行时异常
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 设置对话框的内容面板
|
||||||
setContentPane(contentPane);
|
setContentPane(contentPane);
|
||||||
|
// 设置对话框为模态对话框
|
||||||
setModal(true);
|
setModal(true);
|
||||||
|
// 设置默认按钮为确认按钮
|
||||||
getRootPane().setDefaultButton(buttonOK);
|
getRootPane().setDefaultButton(buttonOK);
|
||||||
|
// 设置对话框标题
|
||||||
setTitle("添加借阅信息");
|
setTitle("添加借阅信息");
|
||||||
|
|
||||||
|
// 为确认按钮添加事件监听器
|
||||||
buttonOK.addActionListener(new ActionListener() {
|
buttonOK.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
// 点击确认按钮时执行的操作
|
||||||
onOK();
|
onOK();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 调整对话框大小以适应内容
|
||||||
pack();
|
pack();
|
||||||
|
// 设置对话框不可调整大小
|
||||||
setResizable(false);
|
setResizable(false);
|
||||||
|
// 设置对话框位置
|
||||||
setLocation();
|
setLocation();
|
||||||
|
// 设置对话框可见
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 点击确认按钮时执行的操作,获取用户输入的借阅信息并更新到数据库中。
|
||||||
|
*/
|
||||||
private void onOK() {
|
private void onOK() {
|
||||||
// 在此处添加您的代码
|
|
||||||
try {
|
try {
|
||||||
this.bID = Integer.valueOf(bIDField.getText());
|
// 获取图书ID
|
||||||
this.sID = Integer.valueOf(sIDField.getText());
|
this.bID = Integer.parseInt(bIDField.getText());
|
||||||
|
// 获取学生ID
|
||||||
|
this.sID = Integer.parseInt(sIDField.getText());
|
||||||
|
// 生成查询SQL语句
|
||||||
searchSQLMaker();
|
searchSQLMaker();
|
||||||
|
// 生成更新SQL语句
|
||||||
updateSQLMaker();
|
updateSQLMaker();
|
||||||
|
// 执行查询图书信息的SQL语句
|
||||||
bIDResult = bConnector.executeQuery(bookSearchSQL);
|
bIDResult = bConnector.executeQuery(bookSearchSQL);
|
||||||
|
// 执行查询学生信息的SQL语句
|
||||||
sIDResult = sConnector.executeQuery(studentSearchSQL);
|
sIDResult = sConnector.executeQuery(studentSearchSQL);
|
||||||
|
// 如果未找到图书信息,弹出错误提示框
|
||||||
if (!bIDResult.next()) {
|
if (!bIDResult.next()) {
|
||||||
JOptionPane.showMessageDialog(this, "未找到该书信息", "错误", JOptionPane.WARNING_MESSAGE);
|
JOptionPane.showMessageDialog(this, "未找到该书信息", "错误", JOptionPane.WARNING_MESSAGE);
|
||||||
} else if (!sIDResult.next()) {
|
}
|
||||||
|
// 如果未找到学生信息,弹出错误提示框
|
||||||
|
else if (!sIDResult.next()) {
|
||||||
JOptionPane.showMessageDialog(this, "未找到学生信息", "错误", JOptionPane.WARNING_MESSAGE);
|
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);
|
JOptionPane.showMessageDialog(this, "该书已借出", "错误", JOptionPane.WARNING_MESSAGE);
|
||||||
}
|
}
|
||||||
|
// 如果图书未借出,更新借阅信息
|
||||||
|
else {
|
||||||
|
bConnector.executeUpdate(updateSQL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
|
// 如果输入的不是整数,弹出错误提示框
|
||||||
JOptionPane.showMessageDialog(this, "请输入一个整数", "错误", JOptionPane.ERROR_MESSAGE);
|
JOptionPane.showMessageDialog(this, "请输入一个整数", "错误", JOptionPane.ERROR_MESSAGE);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
// 抛出运行时异常
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 关闭对话框
|
||||||
dispose();
|
dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置对话框位置,使其居中显示在屏幕上。
|
||||||
|
*/
|
||||||
public void setLocation() {
|
public void setLocation() {
|
||||||
|
// 设置对话框位置,使其居中显示在屏幕上
|
||||||
setLocation(new ScreenSize().width / 2 - getWidth() / 2, new ScreenSize().height / 2 - getHeight() / 2);
|
setLocation(new ScreenSize().width / 2 - getWidth() / 2, new ScreenSize().height / 2 - getHeight() / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成查询SQL语句。
|
||||||
|
*/
|
||||||
private void searchSQLMaker() {
|
private void searchSQLMaker() {
|
||||||
|
// 生成查询图书信息的SQL语句
|
||||||
this.bookSearchSQL = "SELECT * FROM books WHERE book_id =" + this.bID + ";";
|
this.bookSearchSQL = "SELECT * FROM books WHERE book_id =" + this.bID + ";";
|
||||||
|
// 生成查询学生信息的SQL语句
|
||||||
this.studentSearchSQL = "SELECT * FROM students WHERE student_id =" + this.sID + ";";
|
this.studentSearchSQL = "SELECT * FROM students WHERE student_id =" + this.sID + ";";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成更新SQL语句。
|
||||||
|
*/
|
||||||
private void updateSQLMaker() {
|
private void updateSQLMaker() {
|
||||||
|
// 生成更新借阅信息的SQL语句
|
||||||
this.updateSQL = "UPDATE books SET borrowed_by = " + this.sID + " WHERE book_id =" + this.bID + ";";
|
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.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* StudentAdder 类用于添加学生信息的对话框。
|
||||||
|
*/
|
||||||
public class StudentAdder extends JDialog {
|
public class StudentAdder extends JDialog {
|
||||||
|
// 内容面板
|
||||||
private JPanel contentPane;
|
private JPanel contentPane;
|
||||||
|
// 确认按钮
|
||||||
private JButton buttonOK;
|
private JButton buttonOK;
|
||||||
|
// 学生姓名文本框
|
||||||
private JTextField textField1;
|
private JTextField textField1;
|
||||||
|
// 学生ID文本框
|
||||||
private JTextField IDField;
|
private JTextField IDField;
|
||||||
|
// 学生班级文本框
|
||||||
private JTextField textField3;
|
private JTextField textField3;
|
||||||
|
// 男性单选按钮
|
||||||
private JRadioButton maleRadioButton;
|
private JRadioButton maleRadioButton;
|
||||||
|
// 女性单选按钮
|
||||||
private JRadioButton femaleRadioButton;
|
private JRadioButton femaleRadioButton;
|
||||||
|
// 数据库连接器
|
||||||
private Connector connector;
|
private Connector connector;
|
||||||
|
// 学生姓名
|
||||||
private String sName;
|
private String sName;
|
||||||
|
// 学生ID
|
||||||
private int sID;
|
private int sID;
|
||||||
|
// 学生班级
|
||||||
private String sClass;
|
private String sClass;
|
||||||
|
// 学生性别
|
||||||
private String sGender;
|
private String sGender;
|
||||||
|
// 性别按钮组
|
||||||
private ButtonGroup genderGroup;
|
private ButtonGroup genderGroup;
|
||||||
|
// SQL语句
|
||||||
private String sql;
|
private String sql;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* StudentAdder 构造函数,初始化对话框并设置相关属性。
|
||||||
|
*/
|
||||||
public StudentAdder() {
|
public StudentAdder() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// 初始化数据库连接器
|
||||||
connector = new Connector();
|
connector = new Connector();
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
|
// 抛出运行时异常
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
// 抛出运行时异常
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 创建性别按钮组并添加单选按钮
|
||||||
genderGroup = new ButtonGroup();
|
genderGroup = new ButtonGroup();
|
||||||
genderGroup.add(maleRadioButton);
|
genderGroup.add(maleRadioButton);
|
||||||
genderGroup.add(femaleRadioButton);
|
genderGroup.add(femaleRadioButton);
|
||||||
|
|
||||||
|
// 为确认按钮添加事件监听器
|
||||||
buttonOK.addActionListener(new ActionListener() {
|
buttonOK.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
// 点击确认按钮时执行的操作
|
||||||
onOK();
|
onOK();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// 获取最大学生ID并加1作为新学生的ID
|
||||||
sID = getStudentMaxID() + 1;
|
sID = getStudentMaxID() + 1;
|
||||||
|
// 设置学生ID文本框的文本为新学生的ID,并设置为不可编辑
|
||||||
IDField.setText(String.valueOf(sID));
|
IDField.setText(String.valueOf(sID));
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
// 抛出运行时异常
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
IDField.setEditable(false);
|
IDField.setEditable(false);
|
||||||
|
|
||||||
|
// 设置对话框标题
|
||||||
setTitle("添加学生信息");
|
setTitle("添加学生信息");
|
||||||
|
// 设置对话框的内容面板
|
||||||
setContentPane(contentPane);
|
setContentPane(contentPane);
|
||||||
|
// 设置对话框为模态对话框
|
||||||
setModal(true);
|
setModal(true);
|
||||||
|
// 设置默认按钮为确认按钮
|
||||||
getRootPane().setDefaultButton(buttonOK);
|
getRootPane().setDefaultButton(buttonOK);
|
||||||
|
|
||||||
|
// 设置对话框大小
|
||||||
setSize(new Dimension(260, 265));
|
setSize(new Dimension(260, 265));
|
||||||
|
// 设置对话框不可调整大小
|
||||||
setResizable(false);
|
setResizable(false);
|
||||||
|
// 调整对话框大小以适应内容
|
||||||
pack();
|
pack();
|
||||||
|
// 设置对话框位置
|
||||||
setLocation();
|
setLocation();
|
||||||
|
// 设置对话框可见
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置对话框位置,使其居中显示在屏幕上。
|
||||||
|
*/
|
||||||
public void setLocation() {
|
public void setLocation() {
|
||||||
|
// 设置对话框位置,使其居中显示在屏幕上
|
||||||
setLocation(new ScreenSize().width / 2 - getWidth() / 2, new ScreenSize().height / 2 - getHeight() / 2);
|
setLocation(new ScreenSize().width / 2 - getWidth() / 2, new ScreenSize().height / 2 - getHeight() / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 点击确认按钮时执行的操作,获取用户输入的学生信息并插入到数据库中。
|
||||||
|
*/
|
||||||
private void onOK() {
|
private void onOK() {
|
||||||
// 在此处添加您的代码
|
// 获取学生姓名
|
||||||
sName = textField1.getText();
|
sName = textField1.getText();
|
||||||
|
// 获取学生班级
|
||||||
sClass = textField3.getText();
|
sClass = textField3.getText();
|
||||||
|
// 获取学生性别
|
||||||
sGender = maleRadioButton.isSelected() ? "男" : "女";
|
sGender = maleRadioButton.isSelected() ? "男" : "女";
|
||||||
|
// 构建插入学生信息的SQL语句
|
||||||
sql = "INSERT INTO students (student_name,student_id,student_class,student_gender) VALUES ('" + sName + "'," + sID + ",'" + sClass + "','" + sGender + "');";
|
sql = "INSERT INTO students (student_name,student_id,student_class,student_gender) VALUES ('" + sName + "'," + sID + ",'" + sClass + "','" + sGender + "');";
|
||||||
|
// 执行SQL语句
|
||||||
commit2SQL();
|
commit2SQL();
|
||||||
|
// 关闭对话框
|
||||||
dispose();
|
dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行SQL插入操作,将学生信息插入到数据库中。
|
||||||
|
*/
|
||||||
private void commit2SQL() {
|
private void commit2SQL() {
|
||||||
try {
|
try {
|
||||||
|
// 执行SQL插入操作
|
||||||
connector.executeUpdate(sql);
|
connector.executeUpdate(sql);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
// 抛出运行时异常
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取最大学生ID。
|
||||||
|
* @return 最大学生ID
|
||||||
|
* @throws SQLException 如果执行SQL查询时发生错误
|
||||||
|
*/
|
||||||
public int getStudentMaxID() throws SQLException {
|
public int getStudentMaxID() throws SQLException {
|
||||||
|
// 执行SQL查询,获取最大学生ID
|
||||||
ResultSet rs = connector.executeQuery("SELECT MAX(student_id) FROM students;");
|
ResultSet rs = connector.executeQuery("SELECT MAX(student_id) FROM students;");
|
||||||
|
// 将结果集指针移动到第一行
|
||||||
rs.next();
|
rs.next();
|
||||||
|
// 返回最大学生ID
|
||||||
return rs.getInt("MAX(student_id)");
|
return rs.getInt("MAX(student_id)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,33 +6,64 @@ import javax.swing.*;
|
|||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AuthorDIalog 类用于显示作者信息的对话框。
|
||||||
|
*/
|
||||||
public class AuthorDIalog extends JDialog {
|
public class AuthorDIalog extends JDialog {
|
||||||
|
// 内容面板
|
||||||
private JPanel contentPane;
|
private JPanel contentPane;
|
||||||
|
// 确认按钮
|
||||||
private JButton buttonOK;
|
private JButton buttonOK;
|
||||||
|
// 图标面板
|
||||||
private JPanel iconPanel;
|
private JPanel iconPanel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AuthorDIalog 构造函数,初始化对话框并设置相关属性。
|
||||||
|
*/
|
||||||
public AuthorDIalog() {
|
public AuthorDIalog() {
|
||||||
|
// 设置对话框的内容面板
|
||||||
setContentPane(contentPane);
|
setContentPane(contentPane);
|
||||||
|
// 设置对话框为非模态对话框
|
||||||
setModal(false);
|
setModal(false);
|
||||||
|
// 设置默认按钮为确认按钮
|
||||||
getRootPane().setDefaultButton(buttonOK);
|
getRootPane().setDefaultButton(buttonOK);
|
||||||
|
// 设置对话框初始不可见
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
|
|
||||||
|
// 创建作者标签并设置图标
|
||||||
JLabel authorLabel = new JLabel();
|
JLabel authorLabel = new JLabel();
|
||||||
authorLabel.setIcon(new ImageIcon("src/com/msksbr/images/AuthorProfile.jpg"));
|
authorLabel.setIcon(new ImageIcon("src/com/msksbr/images/AuthorProfile.jpg"));
|
||||||
|
// 将作者标签添加到图标面板
|
||||||
iconPanel.add(authorLabel);
|
iconPanel.add(authorLabel);
|
||||||
|
|
||||||
|
// 设置对话框关闭时的操作
|
||||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||||
|
// 设置对话框标题
|
||||||
setTitle("作者");
|
setTitle("作者");
|
||||||
|
|
||||||
|
// 为确认按钮添加事件监听器
|
||||||
buttonOK.addActionListener(new ActionListener() {
|
buttonOK.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
// 点击确认按钮时执行的操作
|
||||||
dispose();
|
dispose();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 设置对话框不可调整大小
|
||||||
setResizable(false);
|
setResizable(false);
|
||||||
|
// 设置对话框始终在最顶层显示
|
||||||
setAlwaysOnTop(true);
|
setAlwaysOnTop(true);
|
||||||
|
// 调整对话框大小以适应内容
|
||||||
pack();
|
pack();
|
||||||
|
// 设置对话框位置
|
||||||
setLocation();
|
setLocation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置对话框位置,使其居中显示在屏幕上。
|
||||||
|
*/
|
||||||
public void setLocation() {
|
public void setLocation() {
|
||||||
|
// 设置对话框位置,使其居中显示在屏幕上
|
||||||
setLocation(new ScreenSize().width / 2 - getWidth() / 2, new ScreenSize().height / 2 - getHeight() / 2);
|
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.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MITDialog 类用于显示 MIT 许可证信息的对话框。
|
||||||
|
*/
|
||||||
public class MITDialog extends JDialog {
|
public class MITDialog extends JDialog {
|
||||||
|
// 内容面板
|
||||||
private JPanel contentPane;
|
private JPanel contentPane;
|
||||||
|
// 确认按钮
|
||||||
private JButton buttonOK;
|
private JButton buttonOK;
|
||||||
|
// 显示 MIT 许可证文本的文本面板
|
||||||
private JTextPane MITPane;
|
private JTextPane MITPane;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MITDialog 构造函数,初始化对话框并设置相关属性。
|
||||||
|
*/
|
||||||
public MITDialog() {
|
public MITDialog() {
|
||||||
|
// 设置对话框标题
|
||||||
setTitle("开源信息");
|
setTitle("开源信息");
|
||||||
|
// 设置 MITPane 为不可编辑
|
||||||
MITPane.setEditable(false);
|
MITPane.setEditable(false);
|
||||||
|
// 设置 MITPane 的文本内容为 MIT 许可证信息
|
||||||
MITPane.setText("MIT License\n" +
|
MITPane.setText("MIT License\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"Copyright (c) 2024 御坂昴\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" +
|
"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" +
|
"OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n" +
|
||||||
"SOFTWARE.\n");
|
"SOFTWARE.\n");
|
||||||
|
// 设置对话框的内容面板
|
||||||
setContentPane(contentPane);
|
setContentPane(contentPane);
|
||||||
|
// 设置对话框为模态对话框
|
||||||
setModal(true);
|
setModal(true);
|
||||||
|
// 设置默认按钮为确认按钮
|
||||||
getRootPane().setDefaultButton(buttonOK);
|
getRootPane().setDefaultButton(buttonOK);
|
||||||
|
// 设置对话框为非模态对话框
|
||||||
setModal(false);
|
setModal(false);
|
||||||
|
|
||||||
|
// 为确认按钮添加事件监听器
|
||||||
buttonOK.addActionListener(new ActionListener() {
|
buttonOK.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
// 点击确认按钮时执行的操作
|
||||||
onOK();
|
onOK();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 调整对话框大小以适应内容
|
||||||
pack();
|
pack();
|
||||||
|
// 设置对话框不可调整大小
|
||||||
setResizable(false);
|
setResizable(false);
|
||||||
|
// 设置对话框位置
|
||||||
setLocation();
|
setLocation();
|
||||||
|
// 设置对话框始终在最顶层显示
|
||||||
setAlwaysOnTop(true);
|
setAlwaysOnTop(true);
|
||||||
|
// 设置对话框可见
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 点击确认按钮时执行的操作,关闭对话框。
|
||||||
|
*/
|
||||||
private void onOK() {
|
private void onOK() {
|
||||||
// 在此处添加您的代码
|
// 关闭对话框
|
||||||
dispose();
|
dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置对话框位置,使其居中显示在屏幕上。
|
||||||
|
*/
|
||||||
public void setLocation() {
|
public void setLocation() {
|
||||||
|
// 设置对话框位置,使其居中显示在屏幕上
|
||||||
setLocation(new ScreenSize().width / 2 - getWidth() / 2, new ScreenSize().height / 2 - getHeight() / 2);
|
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.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remover 类用于删除数据库中的记录。
|
||||||
|
*/
|
||||||
public class Remover extends JDialog {
|
public class Remover extends JDialog {
|
||||||
|
// 内容面板
|
||||||
private JPanel contentPane;
|
private JPanel contentPane;
|
||||||
|
// 确认按钮
|
||||||
private JButton buttonOK;
|
private JButton buttonOK;
|
||||||
|
// 标签,用于显示提示信息
|
||||||
private JLabel idLable;
|
private JLabel idLable;
|
||||||
|
// 文本框,用于输入要删除的记录的ID
|
||||||
private JTextField idField;
|
private JTextField idField;
|
||||||
|
// 要操作的表名
|
||||||
private String table;
|
private String table;
|
||||||
|
// 搜索SQL语句
|
||||||
private String Searchsql;
|
private String Searchsql;
|
||||||
|
// 搜索SQL语句
|
||||||
private String searchSQL;
|
private String searchSQL;
|
||||||
|
// 删除SQL语句
|
||||||
private String deleteSQL;
|
private String deleteSQL;
|
||||||
|
// 搜索错误信息
|
||||||
private String searchErrMsg;
|
private String searchErrMsg;
|
||||||
|
// 要删除的记录的ID
|
||||||
private int id;
|
private int id;
|
||||||
|
// 用于执行搜索操作的数据库连接器
|
||||||
private Connector searchConnector;
|
private Connector searchConnector;
|
||||||
|
// 用于执行删除操作的数据库连接器
|
||||||
private Connector deleteConnector;
|
private Connector deleteConnector;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remover 构造函数,初始化对话框并设置相关属性。
|
||||||
|
* @param table 要操作的表名
|
||||||
|
*/
|
||||||
public Remover(String table) {
|
public Remover(String table) {
|
||||||
try {
|
try {
|
||||||
|
// 初始化搜索和删除连接器
|
||||||
searchConnector = new Connector();
|
searchConnector = new Connector();
|
||||||
deleteConnector = new Connector();
|
deleteConnector = new Connector();
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
|
// 抛出运行时异常
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
// 抛出运行时异常
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
// 为确认按钮添加事件监听器
|
||||||
buttonOK.addActionListener(new ActionListener() {
|
buttonOK.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
// 点击确认按钮时执行的操作
|
||||||
onOK();
|
onOK();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// 设置要操作的表名
|
||||||
this.table = table;
|
this.table = table;
|
||||||
|
// 根据表名设置对话框标题和提示信息
|
||||||
if (table.equals("books")) {
|
if (table.equals("books")) {
|
||||||
setTitle("删除图书信息");
|
setTitle("删除图书信息");
|
||||||
idLable.setText("请输入书号:");
|
idLable.setText("请输入书号:");
|
||||||
@@ -51,36 +77,58 @@ public class Remover extends JDialog {
|
|||||||
idLable.setText("请输入书号:");
|
idLable.setText("请输入书号:");
|
||||||
searchErrMsg = "未找到该借阅信息";
|
searchErrMsg = "未找到该借阅信息";
|
||||||
}
|
}
|
||||||
|
// 设置对话框的内容面板
|
||||||
setContentPane(contentPane);
|
setContentPane(contentPane);
|
||||||
|
// 设置对话框为模态对话框
|
||||||
setModal(true);
|
setModal(true);
|
||||||
|
// 设置默认按钮为确认按钮
|
||||||
getRootPane().setDefaultButton(buttonOK);
|
getRootPane().setDefaultButton(buttonOK);
|
||||||
|
// 调整对话框大小以适应内容
|
||||||
pack();
|
pack();
|
||||||
|
// 设置对话框不可调整大小
|
||||||
setResizable(false);
|
setResizable(false);
|
||||||
|
// 设置对话框位置
|
||||||
setLocation();
|
setLocation();
|
||||||
|
// 设置对话框可见
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 点击确认按钮时执行的操作,删除指定的记录。
|
||||||
|
*/
|
||||||
private void onOK() {
|
private void onOK() {
|
||||||
// 在此处添加您的代码
|
|
||||||
try {
|
try {
|
||||||
|
// 获取要删除的记录的ID
|
||||||
this.id = Integer.valueOf(idField.getText());
|
this.id = Integer.valueOf(idField.getText());
|
||||||
|
// 生成搜索SQL语句
|
||||||
searchSQLMaker();
|
searchSQLMaker();
|
||||||
|
// 生成删除SQL语句
|
||||||
deleteSQLMaker();
|
deleteSQLMaker();
|
||||||
|
// 执行搜索操作
|
||||||
ResultSet rs = searchConnector.executeQuery(searchSQL);
|
ResultSet rs = searchConnector.executeQuery(searchSQL);
|
||||||
|
// 如果找到记录,则执行删除操作
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
deleteConnector.executeUpdate(deleteSQL);
|
deleteConnector.executeUpdate(deleteSQL);
|
||||||
} else {
|
} else {
|
||||||
|
// 如果未找到记录,则显示错误信息
|
||||||
JOptionPane.showMessageDialog(this, searchErrMsg, "错误", JOptionPane.WARNING_MESSAGE);
|
JOptionPane.showMessageDialog(this, searchErrMsg, "错误", JOptionPane.WARNING_MESSAGE);
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
|
// 如果输入的ID不是整数,则显示错误信息
|
||||||
JOptionPane.showMessageDialog(this, "请输入一个整数", "错误", JOptionPane.ERROR_MESSAGE);
|
JOptionPane.showMessageDialog(this, "请输入一个整数", "错误", JOptionPane.ERROR_MESSAGE);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
// 抛出运行时异常
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
// 关闭对话框
|
||||||
dispose();
|
dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成搜索SQL语句。
|
||||||
|
*/
|
||||||
private void searchSQLMaker() {
|
private void searchSQLMaker() {
|
||||||
|
// 根据表名生成搜索SQL语句
|
||||||
if (table.equals("books")) {
|
if (table.equals("books")) {
|
||||||
searchSQL = "select * from " + table + " where book_id=" + id + ";";
|
searchSQL = "select * from " + table + " where book_id=" + id + ";";
|
||||||
} else if (table.equals("students")) {
|
} else if (table.equals("students")) {
|
||||||
@@ -90,7 +138,11 @@ public class Remover extends JDialog {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成删除SQL语句。
|
||||||
|
*/
|
||||||
private void deleteSQLMaker() {
|
private void deleteSQLMaker() {
|
||||||
|
// 根据表名生成删除SQL语句
|
||||||
if (table.equals("books")) {
|
if (table.equals("books")) {
|
||||||
deleteSQL = "delete from " + table + " where book_id=" + id + ";";
|
deleteSQL = "delete from " + table + " where book_id=" + id + ";";
|
||||||
} else if (table.equals("students")) {
|
} else if (table.equals("students")) {
|
||||||
@@ -100,7 +152,11 @@ public class Remover extends JDialog {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置对话框位置,使其居中显示在屏幕上。
|
||||||
|
*/
|
||||||
public void setLocation() {
|
public void setLocation() {
|
||||||
|
// 设置对话框位置,使其居中显示在屏幕上
|
||||||
setLocation(new ScreenSize().width / 2 - getWidth() / 2, new ScreenSize().height / 2 - getHeight() / 2);
|
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.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SearchDIalog 类用于显示查询对话框,并根据用户输入的信息查询数据库中的记录。
|
||||||
|
*/
|
||||||
public class SearchDIalog extends JDialog {
|
public class SearchDIalog extends JDialog {
|
||||||
|
// 用于显示查询结果的标签
|
||||||
public JLabel messageLabel;
|
public JLabel messageLabel;
|
||||||
|
// 用于存储用户输入的ID
|
||||||
protected int idInt;
|
protected int idInt;
|
||||||
|
// 内容面板
|
||||||
private JPanel contentPane;
|
private JPanel contentPane;
|
||||||
|
// 确认按钮
|
||||||
private JButton buttonOK;
|
private JButton buttonOK;
|
||||||
|
// 用于输入ID的文本框
|
||||||
private JTextField idFIeld;
|
private JTextField idFIeld;
|
||||||
|
// 要查询的表名
|
||||||
private String table;
|
private String table;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SearchDIalog 构造函数,初始化对话框并设置相关属性。
|
||||||
|
* @param table 要查询的表名
|
||||||
|
*/
|
||||||
public SearchDIalog(String table) {
|
public SearchDIalog(String table) {
|
||||||
|
// 设置对话框的内容面板
|
||||||
setContentPane(contentPane);
|
setContentPane(contentPane);
|
||||||
|
// 设置对话框为模态对话框
|
||||||
setModal(true);
|
setModal(true);
|
||||||
|
// 设置默认按钮为确认按钮
|
||||||
getRootPane().setDefaultButton(buttonOK);
|
getRootPane().setDefaultButton(buttonOK);
|
||||||
|
// 根据表名设置对话框标题和提示信息
|
||||||
if (table.equals("books")) {
|
if (table.equals("books")) {
|
||||||
this.table = "books";
|
this.table = "books";
|
||||||
this.setTitle("查询图书信息");
|
this.setTitle("查询图书信息");
|
||||||
@@ -36,20 +53,31 @@ public class SearchDIalog extends JDialog {
|
|||||||
this.setTitle("查询借阅信息");
|
this.setTitle("查询借阅信息");
|
||||||
messageLabel.setText("请输入书号:");
|
messageLabel.setText("请输入书号:");
|
||||||
}
|
}
|
||||||
|
// 设置事件监听器
|
||||||
setListener();
|
setListener();
|
||||||
|
// 调整对话框大小以适应内容
|
||||||
pack();
|
pack();
|
||||||
|
// 设置对话框位置
|
||||||
setLocation();
|
setLocation();
|
||||||
|
// 设置对话框可见
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置事件监听器,包括确认按钮的点击事件和文本框的回车键事件。
|
||||||
|
*/
|
||||||
private void setListener() {
|
private void setListener() {
|
||||||
|
// 为确认按钮添加事件监听器
|
||||||
buttonOK.addActionListener(new ActionListener() {
|
buttonOK.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
// 点击确认按钮时执行的操作
|
||||||
onOK();
|
onOK();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
// 为文本框添加键盘事件监听器
|
||||||
idFIeld.addKeyListener(new KeyAdapter() {
|
idFIeld.addKeyListener(new KeyAdapter() {
|
||||||
public void keyPressed(KeyEvent e) {
|
public void keyPressed(KeyEvent e) {
|
||||||
|
// 当用户按下回车键时执行的操作
|
||||||
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||||
onOK();
|
onOK();
|
||||||
}
|
}
|
||||||
@@ -57,16 +85,28 @@ public class SearchDIalog extends JDialog {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置对话框位置,使其居中显示在屏幕上。
|
||||||
|
*/
|
||||||
private void setLocation() {
|
private void setLocation() {
|
||||||
|
// 设置对话框位置,使其居中显示在屏幕上
|
||||||
setLocation(new ScreenSize().width / 2 - getWidth() / 2, new ScreenSize().height / 2 - getHeight() / 2);
|
setLocation(new ScreenSize().width / 2 - getWidth() / 2, new ScreenSize().height / 2 - getHeight() / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 点击确认按钮或按下回车键时执行的操作,查询数据库并显示结果。
|
||||||
|
*/
|
||||||
private void onOK() {
|
private void onOK() {
|
||||||
|
// 执行SQL查询并获取结果集
|
||||||
ResultSet rs = SQLExe();
|
ResultSet rs = SQLExe();
|
||||||
|
// 用于存储查询结果的字符串
|
||||||
String message = "";
|
String message = "";
|
||||||
try {
|
try {
|
||||||
|
// 如果结果集不为空且有下一条记录
|
||||||
if (rs != null && rs.next()) {
|
if (rs != null && rs.next()) {
|
||||||
|
// 用于存储查询结果的标题
|
||||||
String title = "";
|
String title = "";
|
||||||
|
// 根据表名生成查询结果的字符串
|
||||||
if (table.equals("books")) {
|
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");
|
message = "书名:\t" + rs.getString("book_name") + "\n类别:\t" + rs.getString("book_type") + "\n书号:\t" + rs.getInt("book_id") + "\nISBN:\t" + rs.getString("ISBN");
|
||||||
title = "图书信息";
|
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");
|
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 = "借阅信息";
|
title = "借阅信息";
|
||||||
}
|
}
|
||||||
|
// 显示查询结果
|
||||||
new showMessae(message, title);
|
new showMessae(message, title);
|
||||||
} else {
|
} else {
|
||||||
|
// 如果未找到记录,则显示错误信息
|
||||||
JOptionPane.showMessageDialog(this, "未找到", "未找到", JOptionPane.WARNING_MESSAGE);
|
JOptionPane.showMessageDialog(this, "未找到", "未找到", JOptionPane.WARNING_MESSAGE);
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
// 抛出运行时异常
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行SQL查询并返回结果集。
|
||||||
|
* @return 查询结果集
|
||||||
|
*/
|
||||||
private ResultSet SQLExe() {
|
private ResultSet SQLExe() {
|
||||||
|
// 用于存储查询结果集
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
|
// 将用户输入的ID转换为整数
|
||||||
idInt = Integer.valueOf(idFIeld.getText());
|
idInt = Integer.valueOf(idFIeld.getText());
|
||||||
|
// 创建数据库连接器
|
||||||
Connector connector = new Connector();
|
Connector connector = new Connector();
|
||||||
|
// 执行SQL查询并获取结果集
|
||||||
rs = connector.executeQuery(SQLExeMaker(table));
|
rs = connector.executeQuery(SQLExeMaker(table));
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
|
// 如果用户输入的ID不是整数,则显示错误信息
|
||||||
JOptionPane.showMessageDialog(this, "请输入一个整数", "错误", JOptionPane.ERROR_MESSAGE);
|
JOptionPane.showMessageDialog(this, "请输入一个整数", "错误", JOptionPane.ERROR_MESSAGE);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
|
// 抛出运行时异常
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
|
// 抛出运行时异常
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
// 返回查询结果集
|
||||||
return rs;
|
return rs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据表名生成SQL查询语句。
|
||||||
|
* @param table 要查询的表名
|
||||||
|
* @return SQL查询语句
|
||||||
|
*/
|
||||||
private String SQLExeMaker(String table) {
|
private String SQLExeMaker(String table) {
|
||||||
|
// 根据表名生成SQL查询语句
|
||||||
if (table.equals("books")) {
|
if (table.equals("books")) {
|
||||||
return "SELECT * FROM `books` WHERE `book_id` = " + idInt + ";";
|
return "SELECT * FROM `books` WHERE `book_id` = " + idInt + ";";
|
||||||
} else if (table.equals("students")) {
|
} 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">
|
<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"/>
|
<margin top="10" left="10" bottom="10" right="10"/>
|
||||||
<constraints>
|
<constraints>
|
||||||
<xy x="48" y="54" width="436" height="297"/>
|
<xy x="48" y="54" width="573" height="297"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties/>
|
<properties/>
|
||||||
<border type="none"/>
|
<border type="none"/>
|
||||||
@@ -40,7 +40,12 @@
|
|||||||
<properties/>
|
<properties/>
|
||||||
<border type="none"/>
|
<border type="none"/>
|
||||||
<children>
|
<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>
|
||||||
|
<grid id="d3052" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1">
|
||||||
<constraints border-constraint="South"/>
|
<constraints border-constraint="South"/>
|
||||||
<properties/>
|
<properties/>
|
||||||
<border type="none"/>
|
<border type="none"/>
|
||||||
@@ -54,6 +59,24 @@
|
|||||||
</component>
|
</component>
|
||||||
</children>
|
</children>
|
||||||
</grid>
|
</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">
|
<grid id="bae5e" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||||
<constraints border-constraint="Center"/>
|
<constraints border-constraint="Center"/>
|
||||||
<properties/>
|
<properties/>
|
||||||
|
|||||||
@@ -5,40 +5,85 @@ import com.msksbr.LoginFrm.ScreenSize;
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* aboutDIalog 类用于显示关于图书管理系统的对话框。
|
||||||
|
*/
|
||||||
public class aboutDIalog extends JDialog {
|
public class aboutDIalog extends JDialog {
|
||||||
|
// 内容面板
|
||||||
private JPanel contentPane;
|
private JPanel contentPane;
|
||||||
|
// 确认按钮
|
||||||
private JButton buttonOK;
|
private JButton buttonOK;
|
||||||
|
// 图标面板
|
||||||
private JPanel iconPanel;
|
private JPanel iconPanel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* aboutDIalog 构造函数,初始化对话框并设置相关属性。
|
||||||
|
*/
|
||||||
public aboutDIalog() {
|
public aboutDIalog() {
|
||||||
|
// 设置对话框标题
|
||||||
setTitle("关于图书管理系统");
|
setTitle("关于图书管理系统");
|
||||||
|
// 设置对话框初始不可见
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
|
// 设置对话框的内容面板
|
||||||
setContentPane(contentPane);
|
setContentPane(contentPane);
|
||||||
|
// 设置对话框为模态对话框
|
||||||
setModal(true);
|
setModal(true);
|
||||||
|
// 设置默认按钮为确认按钮
|
||||||
getRootPane().setDefaultButton(buttonOK);
|
getRootPane().setDefaultButton(buttonOK);
|
||||||
|
// 设置对话框不可调整大小
|
||||||
setResizable(false);
|
setResizable(false);
|
||||||
|
|
||||||
|
// 创建图标标签并设置图标
|
||||||
JLabel iconLabel = new JLabel();
|
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);
|
iconPanel.add(iconLabel);
|
||||||
|
|
||||||
|
// 设置对话框为非模态对话框
|
||||||
setModal(false);
|
setModal(false);
|
||||||
|
// 设置对话框始终在最顶层显示
|
||||||
setAlwaysOnTop(true);
|
setAlwaysOnTop(true);
|
||||||
|
|
||||||
|
// 为确认按钮添加事件监听器
|
||||||
buttonOK.addActionListener(new ActionListener() {
|
buttonOK.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
// 点击确认按钮时执行的操作
|
||||||
onOK();
|
onOK();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 调整对话框大小以适应内容
|
||||||
pack();
|
pack();
|
||||||
|
// 设置对话框位置
|
||||||
setLocation();
|
setLocation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 点击确认按钮时执行的操作,关闭对话框。
|
||||||
|
*/
|
||||||
private void onOK() {
|
private void onOK() {
|
||||||
// 在此处添加您的代码
|
// 关闭对话框
|
||||||
dispose();
|
dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置对话框位置,使其居中显示在屏幕上。
|
||||||
|
*/
|
||||||
public void setLocation() {
|
public void setLocation() {
|
||||||
|
// 设置对话框位置,使其居中显示在屏幕上
|
||||||
setLocation(new ScreenSize().width / 2 - getWidth() / 2, new ScreenSize().height / 2 - getHeight() / 2);
|
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.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* showMessae 类用于显示一个包含指定消息的模态对话框。
|
||||||
|
*/
|
||||||
public class showMessae extends JDialog {
|
public class showMessae extends JDialog {
|
||||||
|
// 内容面板
|
||||||
private JPanel contentPane;
|
private JPanel contentPane;
|
||||||
|
// 确认按钮
|
||||||
private JButton buttonOK;
|
private JButton buttonOK;
|
||||||
|
// 用于显示消息的文本面板
|
||||||
private JTextPane textPane1;
|
private JTextPane textPane1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* showMessae 构造函数,初始化对话框并设置相关属性。
|
||||||
|
* @param message 要显示的消息内容
|
||||||
|
* @param title 对话框的标题
|
||||||
|
*/
|
||||||
public showMessae(String message, String title) {
|
public showMessae(String message, String title) {
|
||||||
|
// 设置对话框的内容面板
|
||||||
setContentPane(contentPane);
|
setContentPane(contentPane);
|
||||||
|
// 设置对话框为模态对话框
|
||||||
setModal(true);
|
setModal(true);
|
||||||
|
// 设置默认按钮为确认按钮
|
||||||
getRootPane().setDefaultButton(buttonOK);
|
getRootPane().setDefaultButton(buttonOK);
|
||||||
|
|
||||||
|
// 为确认按钮添加事件监听器
|
||||||
buttonOK.addActionListener(new ActionListener() {
|
buttonOK.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
// 点击确认按钮时执行的操作
|
||||||
onOK();
|
onOK();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 设置文本面板的内容为传入的消息
|
||||||
this.textPane1.setText(message);
|
this.textPane1.setText(message);
|
||||||
|
// 设置对话框的标题
|
||||||
this.setTitle(title);
|
this.setTitle(title);
|
||||||
|
// 设置文本面板为不可编辑
|
||||||
textPane1.setEditable(false);
|
textPane1.setEditable(false);
|
||||||
|
// 调整对话框大小以适应内容
|
||||||
pack();
|
pack();
|
||||||
|
// 设置对话框不可调整大小
|
||||||
setResizable(false);
|
setResizable(false);
|
||||||
|
// 设置对话框位置
|
||||||
setCenterLocation();
|
setCenterLocation();
|
||||||
|
// 设置对话框可见
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置对话框位置,使其居中显示在屏幕上。
|
||||||
|
*/
|
||||||
public void setCenterLocation() {
|
public void setCenterLocation() {
|
||||||
|
// 设置对话框位置,使其居中显示在屏幕上
|
||||||
setLocation(new ScreenSize().width / 2 - getWidth() / 2, new ScreenSize().height / 2 - getHeight() / 2);
|
setLocation(new ScreenSize().width / 2 - getWidth() / 2, new ScreenSize().height / 2 - getHeight() / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 点击确认按钮时执行的操作,关闭对话框。
|
||||||
|
*/
|
||||||
private void onOK() {
|
private void onOK() {
|
||||||
// 在此处添加您的代码
|
// 关闭对话框
|
||||||
dispose();
|
dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user