《数据库系统概论》课程报告
课题名称: 小型图书管理系统
课题负责人名(学号): best
同组成员名单(角色):
指导教师: 评阅成绩: 评阅意见:
页脚内容
课 程 设 计
提交报告时间:2015年12月15日
小型图书管理系统
计算机科学与技术 专业
学生 指导老师
[摘要] 随着计算机技术的飞速发展,利用计算机来获得和处理信息是当今信息管理的一大特点。伴随计算机硬件的快速发展,有关信息管理的软件——数据库系统软件也在迅猛发展着。图书馆是高等院校的重要组成部门,是教师和学生获取知识的重要场所。由于图书馆主要从事大量的图书资料的储存和流通。所以一直以来,计算机在图书馆的图书管理中得到了广泛的应用。本系统实现图书信息管理的系统化,规范化和自动化,以最大程度提高操作人员的办公效率。
关键词:JAVA、JDBC、SQL Server、数据库、图书馆管理
页脚内容
课 程 设 计
一、实验题目:小型图书管理系统
二、实验的目的和要求:
完成一个小型图书管理系统,功能要求如下:
1) 能够通过书籍基本信息(包括:书号、书名、出版社、出版日期、作者、内容摘要)单个或以AND方式组合多个条件查询书籍信息;
2) 对于每一种书籍,除可查看其基本信息之外还可查看其总数以及目前在馆数量 3) 可增添新的书籍
4) 可删除已有书籍(如有读者借了该书籍尚未归还,则不允许删除)
5) 可修改书籍的基本信息
6) 能够通过读者基本信息(包括:证号、姓名、性别、系名、年级)单个或以AND方式组合多个条件查询读者信息
7) 对于每位读者除可查看其基本信息之外,还可查看其已借的书籍列表、数量、借还日期 8) 可增添新的读者
9) 可删除已有读者(如该读者有尚未归还的借书,则不允许删除) 10) 可修改读者的基本信息
页脚内容
课 程 设 计
11) 可完成借还书籍的手续
12) 还书时如超期,应该显示超期天数
13) 借书时如果有超期的书没有还,则不允许借书
14) 可查询有哪些读者有超期的书没有还,列出这些读者的基本信息
三、实验的环境:
1、硬件环境:CPU: Intel(R) Core i5-3230 2.60GHz RAM: 8GB
2、软件环境:操作系统:Windows 7 Ultimate SP1 编译软件:Eclipse Luna
Microsoft SQL Server 2014
四、系统ER图
页脚内容
课 程 设 计
添加读者删除读者删除图书修改读者添加图书用户名密码权限修改图书拥有管理员编号书名编号姓名性别年级管理管理作者出版社读者借阅图书出版时间摘要总量系名超期时间应还时间借阅时间现存量 五、表结构定义(使用表格说明)
页脚内容
课 程 设 计
页脚内容
课 程 设 计
页脚内容
课 程 设 计
六、系统功能模块
1) 能够通过书籍基本信息单个或组合多个条件查询书籍信息;
2) 对于每一种书籍,除可查看其基本信息之外还可查看其总数以
页脚内容
课 程 设 计
及目前在馆数量 3) 可增添新的书籍
4) 可删除已有书籍(如有读者借了该书籍尚未归还,则不允许删除)
5) 可修改书籍的基本信息
6) 能够通过读者基本信息单个或组合多个条件查询读者信息 7) 对于每位读者除可查看其基本信息之外,还可查看其已借的书籍列表、数量、借还日期 8) 可增添新的读者
9) 可删除已有读者(如该读者有尚未归还的借书,则不允许删除) 10) 可修改读者的基本信息 11) 可完成借还书籍的手续
12) 还书时如超期,应该显示超期天数
13) 借书时如果有超期的书没有还,则不允许借书
14) 可查询有哪些读者有超期的书没有还,列出这些读者的基本信息
七、程序框架流程图
页脚内容
课 程 设 计
登录主界面图书管理读者管理借阅列表增加书籍编辑书籍删除书籍组合查询借阅书籍归还书籍增加读者编辑读者删除读者组合查询详细信息详细信息
页脚内容
课 程 设 计
九、程序运行结果
页脚内容
课 程 设 计
页脚内容
课 程 设 计
页脚内容
课 程 设 计
页脚内容
课 程 设 计
八、核心代码
AddBook.java
import java.awt.BorderLayout; import java.awt.Container; import java.awt.GridLayout; import java.awt.event.*; import java.util.ArrayList;
页脚内容
课 程 设 计
import javax.swing.*;
public class AddBook extends JFrame implements ActionListener {
JLabel bookNumber = new JLabel(\"Book Number:\"); JLabel bookName = new JLabel(\"Book Name:\"); JLabel bookAuthor = new JLabel(\"Book Author:\"); JLabel press = new JLabel(\"Press:\");
JLabel pressTime = new JLabel(\"Press time:\"); JLabel bookAbstract = new JLabel(\"Abstract:\"); JLabel storage = new JLabel(\"Storage:\"); JLabel remain = new JLabel(\"Remain\");
JLabel remain1 = new JLabel(\"Update with Storage\"); JTextField numberField = new JTextField(); JTextField nameField = new JTextField(); JTextField authorField = new JTextField(); JTextField pressField = new JTextField(); JTextField pressTimeField = new JTextField(); JTextField abstractField = new JTextField(); JTextField storageField = new JTextField(); JButton cancel = new JButton(\"Cancel\"); JButton confirm = new JButton(\"Confirm!!\");
页脚内容
SQLOperation op = new SQLOperation(); Container c = getContentPane(); JPanel p1 = new JPanel();
课 程 设 计
页脚内容
public AddBook() {
c.add(p1, BorderLayout.NORTH);
p1.setLayout(new GridLayout(9, 2, 20, 10)); p1.add(bookNumber); p1.add(numberField); p1.add(bookName); p1.add(nameField); p1.add(bookAuthor); p1.add(authorField); p1.add(press); p1.add(pressField); p1.add(pressTime); p1.add(pressTimeField); p1.add(bookAbstract); p1.add(abstractField); p1.add(storage); p1.add(storageField); p1.add(remain); p1.add(remain1); p1.add(cancel); p1.add(confirm);
cancel.addActionListener(this); confirm.addActionListener(this);
课 程 设 计
}
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub if (e.getSource() == cancel) { }
if (e.getSource() == confirm) {
this.dispose();
BookInfo book = new BookInfo(numberField.getText(),
nameField.getText(), authorField.getText(), pressField.getText(), pressTimeField.getText(), abstractField.getText(), Integer.parseInt(storageField
.getText()),
this.dispose();
Integer.parseInt(storageField.getText()));
ArrayList while (n < Integer.parseInt(strArray.get(0))) { } 页脚内容 n++; if (numberField.getText().equals(strArray.get(n))) { } replicate++; 课 程 设 计 if (replicate == 0) { op.saveBook(book); JOptionPane.showMessageDialog(null, \"Add a book successfully!\", \"Information\", JOptionPane.INFORMATION_MESSAGE); } else { JOptionPane.showMessageDialog(null, \"This book(number) has already existed!\", \"Warning\", } } } } JOptionPane.INFORMATION_MESSAGE); AddReader.java import java.awt.BorderLayout; import java.awt.Container; 页脚内容 课 程 设 计 import java.awt.GridLayout; import java.awt.event.*; import java.util.ArrayList; import javax.swing.*; public class AddReader extends JFrame implements ActionListener { public AddReader() { c.add(p1, BorderLayout.NORTH); 页脚内容 SQLOperation op = new SQLOperation(); Container c = getContentPane(); JPanel p1 = new JPanel(); JLabel readerNumber = new JLabel(\"Reader Number:\"); JLabel readerName = new JLabel(\"Reader Name:\"); JLabel sex = new JLabel(\"Sex:\"); JLabel dpt = new JLabel(\"Department:\"); JLabel grade = new JLabel(\"Grade:\"); JTextField numberField = new JTextField(); JTextField nameField = new JTextField(); JTextField sexField = new JTextField(); JTextField dptField = new JTextField(); JTextField gradeField = new JTextField(); JButton cancel = new JButton(\"Cancel\"); JButton confirm = new JButton(\"Confirm!!\"); 课 程 设 计 } p1.setLayout(new GridLayout(6, 2, 20, 10)); p1.add(readerNumber); p1.add(numberField); p1.add(readerName); p1.add(nameField); p1.add(sex); p1.add(sexField); p1.add(dpt); p1.add(dptField); p1.add(grade); p1.add(gradeField); p1.add(cancel); p1.add(confirm); cancel.addActionListener(this); confirm.addActionListener(this); public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if (e.getSource() == cancel) { } if (e.getSource() == confirm) { this.dispose(); 页脚内容 this.dispose(); 课 程 设 计 ReaderInfo reader = new ReaderInfo(numberField.getText(), nameField.getText(), sexField.getText(), dptField.getText(), Integer.parseInt(gradeField.getText())); ArrayList while (n < Integer.parseInt(strArray.get(0))) { } if (replicate == 0) { if (!sexField.getText().equals(\"boy\") && !sexField.getText().equals(\"girl\")) { n++; if (numberField.getText().equals(strArray.get(n))) { } replicate++; JOptionPane .showMessageDialog( null, \"In the Sex field, you can only input 'boy' or 'girl'!\", \"Warning\", JOptionPane.INFORMATION_MESSAGE); } else { 页脚内容 课 程 设 计 } op.saveReader(reader); JOptionPane.showMessageDialog(null, \"Add a reader successfully!\", \"Information\", JOptionPane.INFORMATION_MESSAGE); } else { JOptionPane.showMessageDialog(null, \"This reader(number) has already existed!\", \"Warning\", } BookDetails.java import java.awt.BorderLayout; import java.awt.Container; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.event.*; 页脚内容 } } } JOptionPane.INFORMATION_MESSAGE); 课 程 设 计 import java.util.ArrayList; import javax.swing.*; import javax.swing.table.DefaultTableModel; public class BookDetails extends JFrame implements ActionListener { JLabel bookNumber = new JLabel(\"Book Number:\"); JLabel bookName = new JLabel(\"Book Name:\"); JLabel author = new JLabel(\"Author:\"); JLabel press = new JLabel(\"Press:\"); JLabel pressTime = new JLabel(\"Press time:\"); JLabel bookAbstract = new JLabel(\"Abstract:\"); JLabel storage = new JLabel(\"Storage:\"); JLabel remain = new JLabel(\"Remain:\"); JLabel numberField = new JLabel(); JLabel nameField = new JLabel(); JLabel authorField = new JLabel(); JLabel pressField = new JLabel(); JLabel pressTimeField = new JLabel(); 页脚内容 SQLOperation op = new SQLOperation(); Container c = getContentPane(); JPanel p1 = new JPanel(); JPanel p2 = new JPanel(); JPanel p3 = new JPanel(); 课 程 设 计 JLabel abstractField = new JLabel(); JLabel storageField = new JLabel(); JLabel remainField = new JLabel(); JButton cancel = new JButton(\"Cancel\"); JLabel details = new JLabel(\"Borrow and reaturn details\"); Object[] s = { \"Reader number\", \"Borrow time\", \"Deadline\", \"Over time\" }; Object[][] ob1 = new Object[7][4]; JTable table = new JTable(ob1, s); JScrollPane scrollPane = new JScrollPane(table); public BookDetails(String number) { BookInfo book = new BookInfo(number); ob1 = op.borrowListForBook(number); for (int i = 0; i < 5; i++) { } ArrayList 页脚内容 DefaultTableModel books = new DefaultTableModel(ob1, s); for (int n = 0; n < 7; n++) { } for (int m = 0; m < 4; m++) { } table.setModel(books); table.invalidate(); ob1[n][m] = this.ob1[n][m]; 课 程 设 计 strArray = op.outputBook(book); numberField.setText(number); nameField.setText(strArray.get(1)); authorField.setText(strArray.get(2)); pressField.setText(strArray.get(3)); pressTimeField.setText(strArray.get(4)); abstractField.setText(strArray.get(5)); storageField.setText(strArray.get(6)); remainField.setText(strArray.get(7)); c.add(p1, BorderLayout.NORTH); c.add(p2, BorderLayout.CENTER); c.add(p3, BorderLayout.SOUTH); p1.setLayout(new GridLayout(9, 2, 20, 10)); p1.add(bookNumber); p1.add(numberField); p1.add(bookName); p1.add(nameField); p1.add(author); p1.add(authorField); p1.add(press); p1.add(pressField); p1.add(pressTime); p1.add(pressTimeField); p1.add(bookAbstract); p1.add(abstractField); 页脚内容 课 程 设 计 } } p1.add(storage); p1.add(storageField); p1.add(remain); p1.add(remainField); p1.add(details); scrollPane.setBounds(0, 0, 800, 300); p2.add(scrollPane); p3.add(cancel); table.setPreferredScrollableViewportSize(new Dimension(400, 100)); cancel.addActionListener(this); public void actionPerformed(ActionEvent e) { } // TODO Auto-generated method stub if (e.getSource() == cancel) { } this.dispose(); BookInfo.java 页脚内容 课 程 设 计 public class BookInfo { public BookInfo(String number, String name, String author, String press, String pressTime, String bookAbstract, int total, int remain) { public BookInfo(String number, String name) { } this.number = number; this.name = name; public BookInfo(String number) { } this.number = number; // default constructor public BookInfo() { } private String number, name, author, press, pressTime, bookAbstract; private int total, remain; this.number = number; this.name = name; this.author = author; this.press = press; this.pressTime = pressTime; this.bookAbstract = bookAbstract; this.total = total; 页脚内容 课 程 设 计 } this.remain = remain; public void setRemain(int i) { } public String getNumber() { } public String getName() { } public String getAuthor() { } public String getPress() { } public String getPressTime() { } public String getBookAbstract() { 页脚内容 this.remain=i; return number; return name; return author; return press; return pressTime; 课 程 设 计 return bookAbstract; } public int getTotal() { return total; } public int getRemain() { return remain; } } BookRetrieval.java import java.awt.BorderLayout; import java.awt.Container; import java.awt.Dimension; import java.awt.Font; import java.awt.GridLayout; import java.awt.event.*; import java.util.ArrayList; 页脚内容 课 程 设 计 import javax.swing.*; import javax.swing.table.DefaultTableModel; class BookRetrieval extends JFrame implements ActionListener { SQLOperation op = new SQLOperation(); Container c = getContentPane(); JPanel p1 = new JPanel(); JPanel p4 = new JPanel(); JPanel p5 = new JPanel(); JLabel bookNumber = new JLabel(\"Book Number:\"); JLabel bookName = new JLabel(\"Book Name:\"); JTextField number = new JTextField(); JTextField name = new JTextField(); JButton back = new JButton(\"Back (Fresh)\"); JButton addBook = new JButton(\"Add a book\"); JButton deleteBook = new JButton(\"Delete a book\"); JButton editBook = new JButton(\"Edit a book\"); JButton search = new JButton(\"Search for details!\"); JButton borrowBook = new JButton(\"Borrow a book\"); JButton returnBook = new JButton(\"Return a book\"); Font font1 = new Font(\"00\", Font.BOLD, 20); Object[] s = { \"Number\", \"Name\", \"Author\", \"Press\", \"Press Time\", \"Abstract\", \"Storage\", \"Remain\" }; Object[][] ob = new Object[40][8]; JTable table = new JTable(ob, s); 页脚内容 课 程 设 计 JScrollPane scrollPane = new JScrollPane(table); public BookRetrieval() { BookInfo book = new BookInfo(); ob = op.allBook(book); for (int i = 0; i < 5; i++) { } c.add(p4, BorderLayout.NORTH); c.add(p1, BorderLayout.CENTER); c.add(p5, BorderLayout.SOUTH); search.setFont(font1); p4.setLayout(new GridLayout(2, 4, 20, 10)); p4.add(back); p4.add(addBook); p4.add(editBook); p4.add(deleteBook); 页脚内容 DefaultTableModel books = new DefaultTableModel(ob, s); for (int n = 0; n < 20; n++) { } for (int m = 0; m < 8; m++) { } table.setModel(books); table.invalidate(); ob[n][m] = this.ob[n][m]; 课 程 设 计 } p4.add(borrowBook); p4.add(returnBook); p1.setLayout(null); scrollPane.setBounds(0, 0, 800, 300); p1.add(scrollPane); p5.setLayout(new GridLayout(5, 1, 0, 0)); p5.add(bookNumber); p5.add(number); p5.add(bookName); p5.add(name); p5.add(search); table.setPreferredScrollableViewportSize(new Dimension(400, 300)); addBook.addActionListener(this); search.addActionListener(this); back.addActionListener(this); deleteBook.addActionListener(this); editBook.addActionListener(this); borrowBook.addActionListener(this); returnBook.addActionListener(this); public void actionPerformed(ActionEvent e) { if (e.getSource() == search) { ArrayList 页脚内容 课 程 设 计 strArray = op.addBookJudgement(); String s1 = number.getText(); String s2 = name.getText(); int n = 0; int replicate = 0; while (n < Integer.parseInt(strArray.get(0))) { } ArrayList while (n1 < Integer.parseInt(strArray1.get(0))) { } if (replicate == 0 && replicate1 == 0) { JOptionPane.showMessageDialog(null, \"Please input a correct book number or name!\", \"Warning\", JOptionPane.INFORMATION_MESSAGE); 页脚内容 n++; if (s1.equals(strArray.get(n))) { } replicate++; n1++; if (s2.equals(strArray1.get(n1))) { } replicate1++; 课 程 设 计 } } else if (replicate != 0 || replicate1 != 0) { } if (replicate == 0 && replicate1 != 0) { BookInfo book = new BookInfo(s1, s2); String s = op.searchBookByName(book); BookDetails f = new BookDetails(s); // f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setTitle(\"Book Details\"); f.setLocation(300, 200); f.setSize(480, 470); f.setVisible(true); } else if (replicate != 0) { } BookDetails f = new BookDetails(s1); // f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setTitle(\"Book Details\"); f.setLocation(300, 200); f.setSize(480, 470); f.setVisible(true); if (e.getSource() == back) { this.dispose(); 页脚内容 课 程 设 计 } MyFrame f = new MyFrame(); // f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setTitle(\"Library Management System\"); f.setLocation(300, 200); f.setSize(580, 300); f.setVisible(true); if (e.getSource() == addBook) { } if (e.getSource() == deleteBook) { } if (e.getSource() == borrowBook) { BorrowBook f = new BorrowBook(); 页脚内容 AddBook f = new AddBook(); // f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setTitle(\"Add a book\"); f.setLocation(300, 200); f.setSize(300, 400); f.setVisible(true); DeleteBook f = new DeleteBook(); // f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setTitle(\"Delete a book\"); f.setLocation(300, 200); f.setSize(300, 200); f.setVisible(true); 课 程 设 计 } } } // f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setTitle(\"Borrow a book\"); f.setLocation(300, 200); f.setSize(300, 200); f.setVisible(true); if (e.getSource() == returnBook) { } if (e.getSource() == editBook) { } SelectEdit f = new SelectEdit(); // f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setTitle(\"Edit a book\"); f.setLocation(300, 200); f.setSize(300, 200); f.setVisible(true); ReturnBook f = new ReturnBook(); // f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setTitle(\"Return a book\"); f.setLocation(300, 200); f.setSize(300, 200); f.setVisible(true); 页脚内容 课 程 设 计 BorrowBook.java import java.awt.BorderLayout; import java.awt.Container; import java.awt.GridLayout; import java.awt.event.*; import java.util.ArrayList; import javax.swing.*; public class BorrowBook extends JFrame implements ActionListener { c.add(p1, BorderLayout.NORTH); p1.setLayout(new GridLayout(3, 2, 20, 10)); 页脚内容 SQLOperation op = new SQLOperation(); Container c = getContentPane(); JPanel p1 = new JPanel(); JLabel bookNumber = new JLabel(\"Book Number:\"); JTextField numberField = new JTextField(); JLabel readerNumber = new JLabel(\"Reader Number:\"); JTextField readerNumberField = new JTextField(); JButton cancel = new JButton(\"Cancel\"); JButton borrow = new JButton(\"Borrow!!\"); public BorrowBook() { 课 程 设 计 } p1.add(bookNumber); p1.add(numberField); p1.add(readerNumber); p1.add(readerNumberField); p1.add(cancel); p1.add(borrow); cancel.addActionListener(this); borrow.addActionListener(this); public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if (e.getSource() == cancel) { } if (e.getSource() == borrow) { String bookNumber = numberField.getText(); ArrayList while (n < Integer.parseInt(strArray.get(0))) { n++; if (bookNumber.equals(strArray.get(n))) { 页脚内容 this.dispose(); 课 程 设 计 } } replicate++; String readerNumber = readerNumberField.getText(); ArrayList while (n1 < Integer.parseInt(strArray1.get(0))) { } if (replicate == 0 || replicate1 == 0) { JOptionPane .showMessageDialog( null, \"Please input a correct book number and a n1++; if (readerNumber.equals(strArray1.get(n1))) { } replicate1++; reader number!\", \"Warning\", JOptionPane.INFORMATION_MESSAGE); } else { 页脚内容 课 程 设 计 BookInfo book = new BookInfo(bookNumber); ArrayList int s1 = op.reBorrowCheck(numberField.getText(), readerNumberField.getText()); if (s1 == 1) { JOptionPane .showMessageDialog( null, \"You have borrowed this book, can not reborrow it!\", \"Unsuccessful\", JOptionPane.INFORMATION_MESSAGE); } else { long currentTime = System.currentTimeMillis(); if (op.deadLineCheck(readerNumberField.getText(), currentTime) != 0) { JOptionPane .showMessageDialog( null, \"You have exceeded the deadline, please return these books first!\", 页脚内容 课 程 设 计 \"Unsuccessful\", JOptionPane.INFORMATION_MESSAGE); } else { BookInfo book1 = new BookInfo(s.get(0), s.get(1), s.get(2), s.get(3), s.get(4), s.get(5), Integer.parseInt(s.get(6)), Integer.parseInt(s.get(7)) - 1); op.inputBook(book1); String borrowTime = Long.toString(System .currentTimeMillis()); String deadline = Long.toString(System .currentTimeMillis() + 2592000000l); System.out.println(borrowTime); System.out.println(deadline); op.insertBorrow(numberField.getText(), readerNumberField.getText(), borrowTime, deadline); JOptionPane .showMessageDialog( null, \"Borrowed this book successfully, you have 30 days to enjoy this book!\", 页脚内容 课 程 设 计 \"Successful\", JOptionPane.INFORMATION_MESSAGE); } } } else { JOptionPane.showMessageDialog(null, \"This book has been borrowed!\", \"Unsuccessful\", } BorrowList.Java import java.awt.BorderLayout; import java.awt.Container; import java.awt.Dimension; 页脚内容 } } } } JOptionPane.INFORMATION_MESSAGE); this.dispose(); 课 程 设 计 import java.awt.Font; import java.awt.GridLayout; import java.awt.event.*; import java.util.ArrayList; import javax.swing.*; import javax.swing.table.DefaultTableModel; public class BorrowList extends JFrame implements ActionListener { SQLOperation op = new SQLOperation(); Container c = getContentPane(); JPanel p1 = new JPanel(); JPanel p2 = new JPanel(); JButton back=new JButton(\"Back\"); Object[] s = { \"Book number\", \"Reader number\", \"Borrow time\", \"Deadline\",\"OverTime\"}; Object[][] ob = new Object[100][5]; JTable table = new JTable(ob, s); JScrollPane scrollPane = new JScrollPane(table); public BorrowList() { // TODO Auto-generated constructor stub Object[][] ob1 = op.borrowList(); for (int i = 0; i < 5; i++) { DefaultTableModel list = new DefaultTableModel(ob, s); 页脚内容 课 程 设 计 } } for (int n = 0; n < 100; n++) { } for (int m = 0; m < 5; m++) { } table.setModel(list); table.invalidate(); ob[n][m] = ob1[n][m]; c.add(p1, BorderLayout.CENTER); c.add(p2,BorderLayout.SOUTH); scrollPane.setBounds(0, 0, 800, 300); p1.add(scrollPane); p2.add(back); table.setPreferredScrollableViewportSize(new Dimension(400, 400)); back.addActionListener(this); public void actionPerformed(ActionEvent e) { if (e.getSource() == back) { this.dispose(); MyFrame f = new MyFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setTitle(\"Library Management System\"); f.setLocation(300, 200); 页脚内容 课 程 设 计 } } } f.setSize(580, 300); f.setVisible(true); // TODO Auto-generated method stub Date.java import java.text.DateFormat; import java.text.SimpleDateFormat; public class Date { public Date(){ } static String borrowTimeInterface(long time) { SimpleDateFormat df = (SimpleDateFormat) DateFormat.getInstance(); } 页脚内容 } df.applyPattern(\"yyyy-MM-dd\"); String s = df.format(time); return s; 课 程 设 计 DeleteBook.java import java.awt.BorderLayout; import java.awt.Container; import java.awt.GridLayout; import java.awt.event.*; import javax.swing.*; public class DeleteBook extends JFrame implements ActionListener { public DeleteBook() { c.add(p1, BorderLayout.NORTH); p1.setLayout(new GridLayout(2, 2, 20, 10)); p1.add(bookNumber); p1.add(numberField); 页脚内容 SQLOperation op = new SQLOperation(); Container c = getContentPane(); JPanel p1 = new JPanel(); JLabel bookNumber = new JLabel(\"Book Number:\"); JTextField numberField = new JTextField(); JButton cancel = new JButton(\"Cancel\"); JButton delete = new JButton(\"Delete!!\"); 课 程 设 计 } p1.add(cancel); p1.add(delete); cancel.addActionListener(this); delete.addActionListener(this); public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if (e.getSource() == cancel) { } if (e.getSource() == delete) { BookInfo book = new BookInfo(numberField.getText()); this.dispose(); if (op.deleteBookCheck(numberField.getText()) != 0) { JOptionPane .showMessageDialog( null, \"Delete the book unsuccessfully. The book this.dispose(); bas been borrowed!\", \"Warning\", JOptionPane.INFORMATION_MESSAGE); } else { if (op.deleteBook(book) == 1) { 页脚内容 课 程 设 计 JOptionPane.showMessageDialog(null, \"Delete the book successfully!\", \"Information\", JOptionPane.INFORMATION_MESSAGE); } else { JOptionPane .showMessageDialog( null, \"Delete the book unsuccessfully. The book does not exist!\", \"Warning\", JOptionPane.INFORMATION_MESSAGE); } DeleteReader.java import java.awt.BorderLayout; import java.awt.Container; import java.awt.GridLayout; 页脚内容 } } } } 课 程 设 计 import java.awt.event.*; import javax.swing.*; public class DeleteReader extends JFrame implements ActionListener { public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub 页脚内容 SQLOperation op = new SQLOperation(); Container c = getContentPane(); JPanel p1 = new JPanel(); JLabel readerNumber = new JLabel(\"Reader Number:\"); JTextField numberField = new JTextField(); JButton cancel = new JButton(\"Cancel\"); JButton delete = new JButton(\"Delete!!\"); public DeleteReader() { } c.add(p1, BorderLayout.NORTH); p1.setLayout(new GridLayout(2, 2, 20, 10)); p1.add(readerNumber); p1.add(numberField); p1.add(cancel); p1.add(delete); cancel.addActionListener(this); delete.addActionListener(this); 课 程 设 计 if (e.getSource() == cancel) { } if (e.getSource() == delete) { ReaderInfo reader = new ReaderInfo(numberField.getText()); this.dispose(); if (op.deleteReaderCheck(numberField.getText()) != 0) { JOptionPane .showMessageDialog( null, \"Delete the reader unsuccessfully. Please this.dispose(); return books first!\", \"Warning\", JOptionPane.INFORMATION_MESSAGE); } else { if (op.deleteReader(reader) == 1) { JOptionPane.showMessageDialog(null, \"Delete the reader successfully!\", \"Information\", JOptionPane.INFORMATION_MESSAGE); } else { JOptionPane .showMessageDialog( null, 页脚内容 课 程 设 计 \"Delete the reader unsuccessfully. The reader does not exist!\", \"Warning\", JOptionPane.INFORMATION_MESSAGE); } EditBook.java import java.awt.BorderLayout; import java.awt.Container; import java.awt.GridLayout; import java.awt.event.*; import java.util.ArrayList; import javax.swing.*; public class EditBook extends JFrame implements ActionListener { SQLOperation op = new SQLOperation(); Container c = getContentPane(); JPanel p1 = new JPanel(); 页脚内容 } } } } 课 程 设 计 public EditBook(String number) { BookInfo book = new BookInfo(number); 页脚内容 JLabel bookNumber = new JLabel(\"Book Number:\"); JLabel bookName = new JLabel(\"Book Name:\"); JLabel author = new JLabel(\"Book Author:\"); JLabel press = new JLabel(\"Press:\"); JLabel pressTime = new JLabel(\"Press time:\"); JLabel bookAbstract = new JLabel(\"Abstract:\"); JLabel storage = new JLabel(\"Storage:\"); JLabel remain = new JLabel(\"Remain:\"); JLabel remain1 = new JLabel(\"Update with storage\"); JLabel numberField = new JLabel(); JTextField nameField = new JTextField(); JTextField authorField = new JTextField(); JTextField pressField = new JTextField(); JTextField pressTimeField = new JTextField(); JTextField abstractField = new JTextField(); JTextField storageField = new JTextField(); JTextField temp1 = new JTextField(); JTextField temp2 = new JTextField(); JButton cancel = new JButton(\"Cancel\"); JButton save = new JButton(\"Save!!\"); 课 程 设 计 ArrayList p1.setLayout(new GridLayout(9, 2, 20, 10)); p1.add(bookNumber); p1.add(numberField); p1.add(bookName); p1.add(nameField); p1.add(author); p1.add(authorField); p1.add(press); p1.add(pressField); p1.add(pressTime); p1.add(pressTimeField); p1.add(bookAbstract); 页脚内容 课 程 设 计 } p1.add(abstractField); p1.add(storage); p1.add(storageField); p1.add(remain); p1.add(remain1); p1.add(cancel); p1.add(save); cancel.addActionListener(this); save.addActionListener(this); public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if (e.getSource() == cancel) { } if (e.getSource() == save) { int i = Integer.parseInt(storageField.getText()) - Integer.parseInt(temp1.getText()) + Integer.parseInt(temp2.getText()); this.dispose(); BookInfo book = new BookInfo(numberField.getText(), nameField.getText(), authorField.getText(), pressField.getText(), pressTimeField.getText(), 页脚内容 课 程 设 计 abstractField.getText(), Integer.parseInt(storageField .getText()), i); op.inputBook(book); JOptionPane.showMessageDialog(null, \"Edit the book successfully!\", } EditReader.java import java.awt.BorderLayout; import java.awt.Container; import java.awt.GridLayout; import java.awt.event.*; import java.util.ArrayList; import javax.swing.*; public class EditReader extends JFrame implements ActionListener { SQLOperation op = new SQLOperation(); Container c = getContentPane(); JPanel p1 = new JPanel(); 页脚内容 } } \"Information\", JOptionPane.INFORMATION_MESSAGE); this.dispose(); 课 程 设 计 页脚内容 JLabel readerNumber = new JLabel(\"Reader Number:\"); JLabel readerName = new JLabel(\"Reader Name:\"); JLabel sex = new JLabel(\"Sex:\"); JLabel dpt = new JLabel(\"Department:\"); JLabel grade = new JLabel(\"Grade:\"); JLabel numberField = new JLabel(); JTextField nameField = new JTextField(); JTextField sexField = new JTextField(); JTextField dptField = new JTextField(); JTextField gradeField = new JTextField(); JButton cancel = new JButton(\"Cancel\"); JButton save = new JButton(\"Save!!\"); public EditReader(String number) { numberField.setText(number); ReaderInfo reader = new ReaderInfo(number); ArrayList 课 程 设 计 } c.add(p1, BorderLayout.NORTH); p1.setLayout(new GridLayout(6, 2, 20, 10)); p1.add(readerNumber); p1.add(numberField); p1.add(readerName); p1.add(nameField); p1.add(sex); p1.add(sexField); p1.add(dpt); p1.add(dptField); p1.add(grade); p1.add(gradeField); p1.add(cancel); p1.add(save); cancel.addActionListener(this); save.addActionListener(this); public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if (e.getSource() == cancel) { } if (e.getSource() == save) { 页脚内容 this.dispose(); 课 程 设 计 ReaderInfo reader = new ReaderInfo(numberField.getText(), nameField.getText(), sexField.getText(), dptField.getText(), Integer.parseInt(gradeField.getText())); if (!sexField.getText().equals(\"boy\") && !sexField.getText().equals(\"girl\")) { JOptionPane .showMessageDialog( null, \"In the Sex field, you can only input 'boy' or 'girl'!\", \"Warning\", JOptionPane.INFORMATION_MESSAGE); } 页脚内容 } } } else { } op.inputReader(reader); JOptionPane.showMessageDialog(null, \"Edit the book successfully!\", \"Information\", JOptionPane.INFORMATION_MESSAGE); this.dispose(); 课 程 设 计 HomePage.java import java.awt.BorderLayout; import java.awt.Container; import java.awt.GridLayout; import java.awt.event.*; import javax.swing.*; import java.awt.Font; public class HomePage { } class MyFrame extends JFrame implements ActionListener { Container c = getContentPane(); JPanel p1 = new JPanel(); JPanel p2 = new JPanel(); JPanel p3 = new JPanel(); JLabel welcome = new JLabel(\"Welcome to my library management system\"); JLabel space = new JLabel(\" \"); JLabel space1 = new JLabel(\" \"); JButton book = new JButton(\"Book Retrieval\"); 页脚内容 课 程 设 计 JButton reader = new JButton(\"Reader Retrieval\"); JButton list = new JButton(\"Borrow List\"); Font font1 = new Font(\"00\", Font.BOLD, 20); Font font2 = new Font(\"00\", Font.ITALIC, 20); public MyFrame() { } c.add(p1, BorderLayout.CENTER); c.add(p2, BorderLayout.EAST); c.add(p3, BorderLayout.WEST); p2.add(space); p3.add(space1); p1.setLayout(new GridLayout(4, 1, 50, 50)); p1.add(welcome); p1.add(book); p1.add(reader); p1.add(list); welcome.setFont(font2); book.setFont(font1); reader.setFont(font1); list.setFont(font1); list.addActionListener(this); book.addActionListener(this); reader.addActionListener(this); 页脚内容 课 程 设 计 public void actionPerformed(ActionEvent e) { if (e.getSource() == book) { } if (e.getSource() == reader) { } if (e.getSource() == list) { this.dispose(); BorrowList page2 = new BorrowList(); page2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); page2.setTitle(\"Borrow List\"); page2.setLocation(200, 100); 页脚内容 this.dispose(); BookRetrieval page1 = new BookRetrieval(); page1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); page1.setTitle(\"Book Retrieval\"); page1.setLocation(200, 100); page1.setSize(815, 600); page1.setVisible(true); this.dispose(); ReaderRetrieval page2 = new ReaderRetrieval(); page2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); page2.setTitle(\"Reader Retrieval\"); page2.setLocation(200, 100); page2.setSize(615, 600); page2.setVisible(true); 课 程 设 计 } } } page2.setSize(495, 515); page2.setVisible(true); LogIn.java import java.awt.BorderLayout; import java.awt.Container; import java.awt.GridLayout; import java.awt.event.*; import javax.management.openmbean.OpenDataException; import javax.swing.*; import java.awt.Font; public class LogIn { My f = new My(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setTitle(\"Log In\"); f.setLocation(300, 200); 页脚内容 public static void main(String[] args) { 课 程 设 计 } } f.setSize(300, 150); f.setVisible(true); class My extends JFrame implements ActionListener { public My() { c.add(p1, BorderLayout.CENTER); c.add(p2, BorderLayout.SOUTH); p1.setLayout(new GridLayout(2, 2, 50, 10)); p1.add(userName); p1.add(nameField); p1.add(password); p1.add(passField); p2.add(confirm); 页脚内容 SQLOperation op = new SQLOperation(); Container c = getContentPane(); JPanel p1 = new JPanel(); JPanel p2 = new JPanel(); JLabel userName = new JLabel(\" User name:\"); JLabel password = new JLabel(\" Password:\"); JTextField nameField = new JTextField(); JPasswordField passField = new JPasswordField(); JButton confirm = new JButton(\"Confirm!\"); 课 程 设 计 } confirm.addActionListener(this); @Override public void actionPerformed(ActionEvent e) { if (e.getSource() == confirm) { } // TODO Auto-generated method stub 页脚内容 String name = nameField.getText(); String pass = passField.getText(); int i = op.logCheck(name, pass); if (i == 1) { this.dispose(); MyFrame f = new MyFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setTitle(\"Library Management System\"); f.setLocation(300, 200); f.setSize(580, 300); f.setVisible(true); } else { } JOptionPane.showMessageDialog(null, \"Please enter a validated username and password!\", \"Warning\", JOptionPane.INFORMATION_MESSAGE); 课 程 设 计 } } ReaderDetails.java import java.awt.BorderLayout; import java.awt.Container; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.event.*; import java.util.ArrayList; import javax.swing.*; import javax.swing.table.DefaultTableModel; public class ReaderDetails extends JFrame implements ActionListener { 页脚内容 SQLOperation op = new SQLOperation(); Container c = getContentPane(); JPanel p1 = new JPanel(); JPanel p2 = new JPanel(); JPanel p3 = new JPanel(); 课 程 设 计 JLabel readerNumber = new JLabel(\"Reader Number:\"); JLabel readerName = new JLabel(\"Reader Name:\"); JLabel sex = new JLabel(\"Sex:\"); JLabel dpt = new JLabel(\"Department:\"); JLabel grade = new JLabel(\"Grade:\"); JLabel numberField = new JLabel(); JLabel nameField = new JLabel(); JLabel sexField = new JLabel(); JLabel dptField = new JLabel(); JLabel gradeField = new JLabel(); JButton cancel = new JButton(\"Cancel\"); JLabel details = new JLabel(\"Borrow and reaturn details\"); Object[] s = { \"Book number\", \"Borrow time\", \"Deadline\", \"Over time\" }; Object[][] ob1 = new Object[7][4]; JTable table = new JTable(ob1, s); JScrollPane scrollPane = new JScrollPane(table); public ReaderDetails(String number) { ReaderInfo reader = new ReaderInfo(number); ob1 = op.borrowListForReader(number); for (int i = 0; i < 5; i++) { DefaultTableModel books = new DefaultTableModel(ob1, s); for (int n = 0; n < 7; n++) { for (int m = 0; m < 4; m++) { 页脚内容 课 程 设 计 } } } ob1[n][m] = this.ob1[n][m]; table.setModel(books); table.invalidate(); ArrayList p1.setLayout(new GridLayout(6, 2, 20, 10)); p1.add(readerNumber); p1.add(numberField); p1.add(readerName); p1.add(nameField); p1.add(sex); p1.add(sexField); p1.add(dpt); 页脚内容 课 程 设 计 } } p1.add(dptField); p1.add(grade); p1.add(gradeField); p1.add(details); scrollPane.setBounds(0, 0, 800, 300); p2.add(scrollPane); p3.add(cancel); table.setPreferredScrollableViewportSize(new Dimension(400, 200)); cancel.addActionListener(this); public void actionPerformed(ActionEvent e) { } // TODO Auto-generated method stub if (e.getSource() == cancel) { } this.dispose(); ReaderInfo.java 页脚内容 课 程 设 计 public class ReaderInfo { public String getNumber() { 页脚内容 private String number, name, sex, dpt; private int grade; // default constructor public ReaderInfo() { } public ReaderInfo(String number) { } public ReaderInfo(String number, String name) { } public ReaderInfo(String number, String name, String sex, String dpt, } int grade) { this.number = number; this.name = name; this.number = number; this.number = number; this.name = name; this.sex = sex; this.dpt = dpt; this.grade = grade; 课 程 设 计 return number; } public String getName() { return name; } public String getSex() { return sex; } public String getDpt() { return dpt; } public int getGrade() { return grade; } } ReaderRetrieval.java import java.awt.BorderLayout; import java.awt.Container; import java.awt.Font; 页脚内容 课 程 设 计 import java.awt.GridLayout; import java.awt.event.*; import java.util.ArrayList; import java.util.Collections; import javax.swing.*; import javax.swing.table.DefaultTableModel; class ReaderRetrieval extends JFrame implements ActionListener { SQLOperation op = new SQLOperation(); Container c = getContentPane(); JPanel p1 = new JPanel(); JPanel p4 = new JPanel(); JPanel p5 = new JPanel(); JLabel readerNumber = new JLabel(\"Reader Number:\"); JLabel readerName = new JLabel(\"Reader Name:\"); JTextField number = new JTextField(); JTextField name = new JTextField(); JButton back = new JButton(\"Back (Fresh)\"); JButton addReader = new JButton(\"Add a reader\"); JButton deleteReader = new JButton(\"Delete a reader\"); JButton editReader = new JButton(\"Edit a reader\"); JButton search = new JButton(\"Search for details!\"); Object[] s = { \"Number\", \"Name\", \"Sex\", \"Department\", \"Grade\" }; Object[][] ob = new Object[20][5]; 页脚内容 课 程 设 计 JTable table = new JTable(ob, s); JScrollPane scrollPane = new JScrollPane(table); Font font1 = new Font(\"00\", Font.BOLD, 20); public ReaderRetrieval() { ReaderInfo reader = new ReaderInfo(); op.allReader(reader); ob = op.allReader(reader); for (int i = 0; i < 5; i++) { } search.setFont(font1); c.add(p4, BorderLayout.NORTH); c.add(p1, BorderLayout.CENTER); c.add(p5, BorderLayout.SOUTH); p4.setLayout(new GridLayout(2, 4, 20, 10)); p4.add(back); 页脚内容 DefaultTableModel readers = new DefaultTableModel(ob, s); for (int n = 0; n < 20; n++) { } for (int m = 0; m < 5; m++) { } table.setModel(readers); table.invalidate(); ob[n][m] = this.ob[n][m]; 课 程 设 计 } p4.add(addReader); p4.add(editReader); p4.add(deleteReader); p1.setLayout(null); scrollPane.setBounds(0, 0, 600, 300); p1.add(scrollPane); p5.setLayout(new GridLayout(5, 1, 0, 0)); p5.add(readerNumber); p5.add(number); p5.add(readerName); p5.add(name); p5.add(search); addReader.addActionListener(this); search.addActionListener(this); back.addActionListener(this); deleteReader.addActionListener(this); editReader.addActionListener(this); public void actionPerformed(ActionEvent e) { if (e.getSource() == search) { ArrayList 页脚内容 课 程 设 计 String s2 = name.getText(); int n = 0; int replicate = 0; while (n < Integer.parseInt(strArray.get(0))) { } ArrayList while (n1 < Integer.parseInt(strArray1.get(0))) { } if (replicate == 0 && replicate1 == 0) { JOptionPane.showMessageDialog(null, \"Please input a correct reader number or name!\", \"Warning\", JOptionPane.INFORMATION_MESSAGE); n1++; if (s2.equals(strArray1.get(n1))) { } replicate1++; n++; if (s1.equals(strArray.get(n))) { } replicate++; } else if (replicate != 0 || replicate1 != 0) { 页脚内容 课 程 设 计 } } if (replicate == 0 && replicate1 != 0) { ReaderInfo reader = new ReaderInfo(s1, s2); String s = op.searchReaderByName(reader); ReaderDetails f = new ReaderDetails(s); //f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setTitle(\"Reader Details\"); f.setLocation(300, 200); f.setSize(480, 470); f.setVisible(true); } else if (replicate != 0) { } ReaderDetails f = new ReaderDetails(s1); //f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setTitle(\"Reader Details\"); f.setLocation(300, 200); f.setSize(480, 470); f.setVisible(true); if (e.getSource() == back) { this.dispose(); MyFrame f = new MyFrame(); 页脚内容 课 程 设 计 } //f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setTitle(\"Library Management System\"); f.setLocation(300, 200); f.setSize(580, 300); f.setVisible(true); if (e.getSource() == addReader) { } if (e.getSource() == deleteReader) { } if (e.getSource() == editReader) { SelectEditReader f = new SelectEditReader(); //f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 页脚内容 AddReader f = new AddReader(); //f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setTitle(\"Add a Reader\"); f.setLocation(300, 200); f.setSize(300, 300); f.setVisible(true); DeleteReader f = new DeleteReader(); //f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setTitle(\"Delete a reader\"); f.setLocation(300, 200); f.setSize(300, 200); f.setVisible(true); 课 程 设 计 } } } f.setTitle(\"Edit a reader\"); f.setLocation(300, 200); f.setSize(300, 200); f.setVisible(true); ReturnBook.java import java.awt.BorderLayout; import java.awt.Container; import java.awt.GridLayout; import java.awt.event.*; import java.util.ArrayList; import javax.management.openmbean.OpenDataException; import javax.swing.*; public class ReturnBook extends JFrame implements ActionListener { SQLOperation op = new SQLOperation(); Container c = getContentPane(); JPanel p1 = new JPanel(); JLabel bookNumber = new JLabel(\"Book Number:\"); JTextField numberField = new JTextField(); 页脚内容 课 程 设 计 JLabel readerNumber = new JLabel(\"Reader Number:\"); JTextField readerNumberField = new JTextField(); JButton cancel = new JButton(\"Cancel\"); JButton returnBook = new JButton(\"Return!!\"); public ReturnBook() { } public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if (e.getSource() == cancel) { } if (e.getSource() == returnBook) { String bookNumber = numberField.getText(); 页脚内容 c.add(p1, BorderLayout.NORTH); p1.setLayout(new GridLayout(3, 2, 20, 10)); p1.add(bookNumber); p1.add(numberField); p1.add(readerNumber); p1.add(readerNumberField); p1.add(cancel); p1.add(returnBook); cancel.addActionListener(this); returnBook.addActionListener(this); this.dispose(); 课 程 设 计 ArrayList while (n < Integer.parseInt(strArray.get(0))) { } String readerNumber = readerNumberField.getText(); ArrayList while (n1 < Integer.parseInt(strArray1.get(0))) { } if (replicate == 0 || replicate1 == 0) { JOptionPane 页脚内容 n++; if (bookNumber.equals(strArray.get(n))) { } replicate++; n1++; if (readerNumber.equals(strArray1.get(n1))) { } replicate1++; 课 程 设 计 .showMessageDialog( null, \"Please input a correct book number and a reader number!\", \"Warning\", JOptionPane.INFORMATION_MESSAGE); } else { if (op.returnCheck(numberField.getText(), readerNumberField.getText()) == 1) { JOptionPane.showMessageDialog(null, \"No result found!\", \"Warning\", JOptionPane.INFORMATION_MESSAGE); } else { BookInfo book = new BookInfo(bookNumber); ArrayList BookInfo book1 = new BookInfo(s.get(0), s.get(1), s.get(2), s.get(3), s.get(4), s.get(5), Integer.parseInt(s.get(6)), Integer.parseInt(s.get(7)) + 1); op.inputBook(book1); if(op.deleteResult(numberField.getText(), readerNumberField.getText())==1){ 页脚内容 课 程 设 计 JOptionPane.showMessageDialog(null, \"Return the book successful!\", \"Successful\", JOptionPane.INFORMATION_MESSAGE); this.dispose(); }else{ JOptionPane.showMessageDialog(null, \"Failed to return the book!\", \"Unsuccessful\", JOptionPane.INFORMATION_MESSAGE); } SelectEdit.java import java.awt.BorderLayout; import java.awt.Container; 页脚内容 } } } } } 课 程 设 计 import java.awt.GridLayout; import java.awt.event.*; import javax.swing.*; public class SelectEdit extends JFrame implements ActionListener { } 页脚内容 SQLOperation op = new SQLOperation(); BookInfo book = new BookInfo(); Container c = getContentPane(); JPanel p1 = new JPanel(); JLabel bookNumber = new JLabel(\"Book Number:\"); JTextField numberField = new JTextField(); JButton cancel = new JButton(\"Cancel\"); JButton select = new JButton(\"Select!!\"); public SelectEdit() { c.add(p1, BorderLayout.NORTH); p1.setLayout(new GridLayout(2, 2, 20, 10)); p1.add(bookNumber); p1.add(numberField); p1.add(cancel); p1.add(select); cancel.addActionListener(this); select.addActionListener(this); 课 程 设 计 } catch (Exception e2) { JOptionPane.showMessageDialog(null, \"Please input the this.dispose(); try { EditBook f = new EditBook(numberField.getText()); //f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setTitle(\"Edit a book\"); f.setLocation(300, 200); f.setSize(300, 400); f.setVisible(true); public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if (e.getSource() == cancel) { } if (e.getSource() == select) { this.dispose(); book number correctly!\", } 页脚内容 } } \"Warning\", JOptionPane.INFORMATION_MESSAGE); // TODO: handle exception 课 程 设 计 } SelectEditReader.java import java.awt.BorderLayout; import java.awt.Container; import java.awt.GridLayout; import java.awt.event.*; import javax.swing.*; public class SelectEditReader extends JFrame implements ActionListener { public SelectEditReader() { c.add(p1, BorderLayout.NORTH); p1.setLayout(new GridLayout(2, 2, 20, 10)); p1.add(readerNumber); p1.add(numberField); 页脚内容 Container c = getContentPane(); JPanel p1 = new JPanel(); JLabel readerNumber = new JLabel(\"Reader Number:\"); JTextField numberField = new JTextField(); JButton cancel = new JButton(\"Cancel\"); JButton select = new JButton(\"Select!!\"); 课 程 设 计 } p1.add(cancel); p1.add(select); cancel.addActionListener(this); select.addActionListener(this); public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if (e.getSource() == cancel) { } if (e.getSource() == select) { this.dispose(); try { EditReader f = new EditReader(numberField.getText()); //f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setTitle(\"Edit a reader\"); f.setLocation(300, 200); f.setSize(300, 300); f.setVisible(true); this.dispose(); } catch (Exception e2) { JOptionPane.showMessageDialog(null, \"Please input the reader number correctly!\", \"Warning\", 页脚内容 课 程 设 计 } } } } JOptionPane.INFORMATION_MESSAGE); // TODO: handle exception SQLOperation.java import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; public class SQLOperation { public SQLOperation() { try { Class.forName(\"com.microsoft.sqlserver.jdbc.SQLServerDriver\"); ct = DriverManager.getConnection( 页脚内容 static PreparedStatement ps = null; static Connection ct = null; static ResultSet rs = null; 课 程 设 计 \"jdbc:sqlserver://127.0.0.1:1433;DatabaseName=Library\", } public int logCheck(String name, String password) { int i = 0; try { ArrayList PreparedStatement ps = ct.prepareStatement(sql); // ps.setString(1, book.getNumber()); rs = ps.executeQuery(); int count = 0; while (rs.next()) { } if (strArray.get(0).equals(name) 页脚内容 \"sa\", \"123456\"); } catch (Exception e) { } e.printStackTrace(); // TODO: handle exception String s = rs.getString(\"登录名\"); strArray.add(s); s = rs.getString(\"密码\"); strArray.add(s); 课 程 设 计 } } && strArray.get(1).equals(password)) { i = 1; } catch (Exception e) { } System.out.print(i); return i; System.out.println(e); public ArrayList addBookJudgement1() { ArrayList String sql = \"select 书名 FROM 图书信息\"; PreparedStatement ps = ct.prepareStatement(sql); // ps.setString(1, book.getNumber()); rs = ps.executeQuery(); int count = 0; while (rs.next()) { } 页脚内容 String s = rs.getString(\"书名\"); strArray.add(s); count++; 课 程 设 计 } strArray.add(Integer.toString(count)); for (; count >= 0; count--) { } strArray1.add(strArray.get(count)); } catch (Exception e) { } return strArray1; System.out.println(e); public ArrayList addReaderJudgement1() { ArrayList String sql = \"select 姓名 FROM 读者信息\"; PreparedStatement ps = ct.prepareStatement(sql); // ps.setString(1, book.getNumber()); rs = ps.executeQuery(); int count = 0; while (rs.next()) { } strArray.add(Integer.toString(count)); 页脚内容 String s = rs.getString(\"姓名\"); strArray.add(s); count++; 课 程 设 计 } for (; count >= 0; count--) { } strArray1.add(strArray.get(count)); } catch (Exception e) { } return strArray1; System.out.println(e); public ArrayList addBookJudgement() { ArrayList String sql = \"select 编号 FROM 图书信息\"; PreparedStatement ps = ct.prepareStatement(sql); // ps.setString(1, book.getNumber()); rs = ps.executeQuery(); int count = 0; while (rs.next()) { } strArray.add(Integer.toString(count)); for (; count >= 0; count--) { 页脚内容 String s = rs.getString(\"编号\"); strArray.add(s); count++; 课 程 设 计 } } strArray1.add(strArray.get(count)); } catch (Exception e) { } return strArray1; System.out.println(e); public ArrayList addReaderJudgement() { ArrayList String sql = \"select 编号 FROM 读者信息\"; PreparedStatement ps = ct.prepareStatement(sql); rs = ps.executeQuery(); int count = 0; while (rs.next()) { } strArray.add(Integer.toString(count)); for (; count >= 0; count--) { } 页脚内容 String s = rs.getString(\"编号\"); strArray.add(s); count++; strArray1.add(strArray.get(count)); 课 程 设 计 } } catch (Exception e) { } return strArray1; System.out.println(e); public void saveReader(ReaderInfo reader) { try { String sql = \"INSERT INTO 读者信息(编号,姓名,性别,系名,年级) VALUES (?,?,?,?,?);\"; public void saveBook(BookInfo book) { try { String sql = \"INSERT INTO 图书信息(编号,书名,作者,出版社,出 页脚内容 } PreparedStatement pts = ct.prepareStatement(sql); pts.setString(1, reader.getNumber()); pts.setString(2, reader.getName()); pts.setString(3, reader.getSex()); pts.setString(4, reader.getDpt()); pts.setInt(5, reader.getGrade()); pts.executeUpdate(); } catch (Exception e) { } System.out.println(e); 课 程 设 计 版日期,摘要,总量,现存量) VALUES (?,?,?,?,?,?,?,?);\"; public String searchBookByName(BookInfo book) { String s = null; try { String sql = \"select 编号 FROM 图书信息 where 书名=?;\"; PreparedStatement ps = ct.prepareStatement(sql); ps.setString(1, book.getName()); rs = ps.executeQuery(); while (rs.next()) { s = rs.getString(\"编号\"); 页脚内容 } PreparedStatement pts = ct.prepareStatement(sql); pts.setString(1, book.getNumber()); pts.setString(2, book.getName()); pts.setString(3, book.getAuthor()); pts.setString(4, book.getPress()); pts.setString(5, book.getPressTime()); pts.setString(6, book.getBookAbstract()); pts.setInt(7, book.getTotal()); pts.setInt(8, book.getRemain()); pts.executeUpdate(); } catch (Exception e) { } System.out.print(e); 课 程 设 计 } } } catch (Exception e) { } return s; System.out.println(e); public String searchReaderByName(ReaderInfo reader) { } public int deleteBook(BookInfo book) { try { 页脚内容 String s = null; try { String sql = \"select 编号 FROM 读者信息 where 姓名=?;\"; PreparedStatement pts = ct.prepareStatement(sql); pts.setString(1, reader.getName()); rs = pts.executeQuery(); while (rs.next()) { } s = rs.getString(\"编号\"); } catch (Exception e) { } return s; System.out.println(e); 课 程 设 计 } String sql = \"delete FROM 图书信息 where 编号=?;\"; PreparedStatement pts = ct.prepareStatement(sql); pts.setString(1, book.getNumber()); int count = pts.executeUpdate(); if (count == 1) { return 1; } else { } return 0; } catch (Exception e) { } System.out.println(e); return 0; public int deleteReader(ReaderInfo reader) { try { String sql = \"delete FROM 读者信息 where 编号=?;\"; PreparedStatement pts = ct.prepareStatement(sql); pts.setString(1, reader.getNumber()); int count = pts.executeUpdate(); if (count == 1) { return 1; } else { return 0; 页脚内容 课 程 设 计 } } } catch (Exception e) { } System.out.println(e); return 0; public ArrayList outputBook(BookInfo book) { ArrayList String sql = \"select * FROM 图书信息 where 编号=?;\"; PreparedStatement ps = ct.prepareStatement(sql); ps.setString(1, book.getNumber()); rs = ps.executeQuery(); while (rs.next()) { String s = rs.getString(\"编号\"); strArray.add(s); s = rs.getString(\"书名\"); strArray.add(s); s = rs.getString(\"作者\"); strArray.add(s); s = rs.getString(\"出版社\"); strArray.add(s); s = rs.getString(\"出版日期\"); strArray.add(s); 页脚内容 课 程 设 计 } } s = rs.getString(\"摘要\"); strArray.add(s); s = rs.getString(\"总量\"); strArray.add(s); s = rs.getString(\"现存量\"); strArray.add(s); } catch (Exception e) { } return strArray; System.out.println(e); public ArrayList outputReader(ReaderInfo reader) { ArrayList String sql = \"select * FROM 读者信息 where 编号=?;\"; PreparedStatement ps = ct.prepareStatement(sql); ps.setString(1, reader.getNumber()); rs = ps.executeQuery(); while (rs.next()) { String s = rs.getString(\"编号\"); strArray.add(s); s = rs.getString(\"姓名\"); strArray.add(s); 页脚内容 课 程 设 计 } } s = rs.getString(\"性别\"); strArray.add(s); s = rs.getString(\"系名\"); strArray.add(s); s = rs.getString(\"年级\"); strArray.add(s); } catch (Exception e) { } return strArray; System.out.println(e); public void inputBook(BookInfo book) { ArrayList String sql = \"update 图书信息 set 书名=?,作者=?,出版社=?,出 版日期=?,摘要=?,总量=?,现存量=? where 编号=?;\"; PreparedStatement pts = ct.prepareStatement(sql); pts.setString(1, book.getName()); pts.setString(2, book.getAuthor()); pts.setString(3, book.getPress()); pts.setString(4, book.getPressTime()); pts.setString(5, book.getBookAbstract()); pts.setInt(6, book.getTotal()); 页脚内容 课 程 设 计 } pts.setInt(7, book.getRemain()); pts.setString(8, book.getNumber()); pts.executeUpdate(); } catch (Exception e) { } System.out.println(e); public void inputReader(ReaderInfo reader) { try { String sql = \"update 读者信息 set 姓名=?,性别=?,系名=?,年级=? where 编号=?;\"; public Object[][] allBook(BookInfo book) { 页脚内容 } PreparedStatement pts = ct.prepareStatement(sql); pts.setString(1, reader.getName()); pts.setString(2, reader.getSex()); pts.setString(3, reader.getDpt()); pts.setInt(4, reader.getGrade()); pts.setString(5, reader.getNumber()); pts.executeUpdate(); } catch (Exception e) { } System.out.println(e); 课 程 设 计 } Object[][] ob = new Object[60][8]; int n = 0; try { String sql = \"select * FROM 图书信息\"; PreparedStatement ps = ct.prepareStatement(sql); rs = ps.executeQuery(); while (rs.next()) { } ob[n][0] = rs.getString(\"编号\"); ob[n][1] = rs.getString(\"书名\"); ob[n][2] = rs.getString(\"作者\"); ob[n][3] = rs.getString(\"出版社\"); ob[n][4] = rs.getString(\"出版日期\"); ob[n][5] = rs.getString(\"摘要\"); ob[n][6] = rs.getString(\"总量\"); ob[n][7] = rs.getString(\"现存量\"); n++; } catch (Exception e) { } return ob; System.out.println(e); public Object[][] allReader(ReaderInfo reader) { Object[][] ob = new Object[60][5]; 页脚内容 课 程 设 计 } int n = 0; try { String sql = \"select * FROM 读者信息\"; PreparedStatement ps = ct.prepareStatement(sql); rs = ps.executeQuery(); while (rs.next()) { } ob[n][0] = rs.getString(\"编号\"); ob[n][1] = rs.getString(\"姓名\"); ob[n][2] = rs.getString(\"性别\"); ob[n][3] = rs.getString(\"系名\"); ob[n][4] = rs.getString(\"年级\"); n++; } catch (Exception e) { } return ob; System.out.println(e); public void insertBorrow(String bookNumber, String readerNumber, String borrowTime, String deadline) { try { String sql = \"Insert into 图书借阅 ( 图书编号 , 读者编号,借阅 时间, 应还时间) values(?,?,?,?)\"; PreparedStatement pts = ct.prepareStatement(sql); 页脚内容 课 程 设 计 } pts.setString(1, bookNumber); pts.setString(2, readerNumber); pts.setString(3, borrowTime); pts.setString(4, deadline); pts.executeUpdate(); } catch (Exception e) { } System.out.println(e); public int reBorrowCheck(String bookNumber, String readerNumber) { int i = 0; ArrayList String sql = \"select * FROM 图书借阅 where 图书编号=? and 读者编号=?\"; PreparedStatement ps = ct.prepareStatement(sql); ps.setString(1, bookNumber); ps.setString(2, readerNumber); rs = ps.executeQuery(); int count = 0; while (rs.next()) { String s = rs.getString(\"图书编号\"); strArray.add(s); 页脚内容 课 程 设 计 } } s = rs.getString(\"读者编号\"); strArray.add(s); count++; System.out.println(strArray); if (count >= 1) { } i = 1; } catch (Exception e) { } return i; System.out.println(e); public int deadLineCheck(String readerNumber, long currentTime) { int i = 0; ArrayList String sql = \"select * FROM 图书借阅 where 读者编号=?\"; PreparedStatement ps = ct.prepareStatement(sql); ps.setString(1, readerNumber); rs = ps.executeQuery(); int count = 0; while (rs.next()) { 页脚内容 课 程 设 计 } } String s = rs.getString(\"应还时间\"); strArray.add(s); count++; for (; count > 0; count--) { } if (Long.parseLong(strArray.get(count - 1)) <= currentTime) { } i++; } catch (Exception e) { } return i; System.out.println(e); public int returnCheck(String bookNumber, String readerNumber) { int i = 0; ArrayList String sql = \"select * FROM 图书借阅 where 图书编号=? and 读者编号=?\"; PreparedStatement ps = ct.prepareStatement(sql); ps.setString(1, bookNumber); ps.setString(2, readerNumber); rs = ps.executeQuery(); 页脚内容 课 程 设 计 } while (rs.next()) { } System.out.println(strArray); if (strArray.get(0) != bookNumber } || strArray.get(1) != readerNumber) { String s = rs.getString(\"图书编号\"); strArray.add(s); s = rs.getString(\"读者编号\"); strArray.add(s); i = 0; } catch (Exception e) { } System.out.print(i); return i; System.out.println(e); i = 1; public int deleteResult(String bookNumber, String readerNumber) { try { String sql = \"delete FROM 图书借阅 where 图书编号=? and 读 者编号=?;\"; PreparedStatement pts = ct.prepareStatement(sql); 页脚内容 课 程 设 计 } pts.setString(1, bookNumber); pts.setString(2, readerNumber); int count = pts.executeUpdate(); if (count == 1) { return 1; } else { } return 0; } catch (Exception e) { } System.out.println(e); return 0; public Object[][] borrowList() { Date dateCal = new Date(); Object[][] ob = new Object[100][5]; int n = 0; try { String sql = \"select * FROM 图书借阅\"; PreparedStatement ps = ct.prepareStatement(sql); rs = ps.executeQuery(); while (rs.next()) { ob[n][0] = rs.getString(\"图书编号\"); ob[n][1] = rs.getString(\"读者编号\"); 页脚内容 课 程 设 计 String s = dateCal.borrowTimeInterface(Long.parseLong(rs .getString(\"借阅时间\"))); ob[n][2] = s; long re = Long.parseLong(rs.getString(\"应还时间\")); s = dateCal.borrowTimeInterface(re); ob[n][3] = s; long re1 = System.currentTimeMillis(); if (re1 > re) { ob[n][4] = Long.toString(((re1 - re) / 86400000)+1) + \" Days\"; public Object[][] borrowListForReader(String readerNumber) { Date dateCal = new Date(); Object[][] ob = new Object[100][4]; int n = 0; 页脚内容 } } } else { } n++; ob[n][4] = \"NOT\"; } catch (Exception e) { } return ob; System.out.println(e); 课 程 设 计 try { String sql = \"select * FROM 图书借阅 where 读者编号=?\"; PreparedStatement ps = ct.prepareStatement(sql); ps.setString(1, readerNumber); rs = ps.executeQuery(); while (rs.next()) { ob[n][0] = rs.getString(\"图书编号\"); String s = dateCal.borrowTimeInterface(Long.parseLong(rs .getString(\"借阅时间\"))); ob[n][1] = s; long re = Long.parseLong(rs.getString(\"应还时间\")); s = dateCal.borrowTimeInterface(re); ob[n][2] = s; long re1 = System.currentTimeMillis(); if (re1 > re) { ob[n][3] = Long.toString(((re1 - re) / 86400000)+1) + \" Days\"; } } else { } n++; ob[n][3] = \"NOT\"; } catch (Exception e) { } 页脚内容 System.out.println(e); 课 程 设 计 } return ob; public Object[][] borrowListForBook(String bookNumber) { Date dateCal = new Date(); Object[][] ob = new Object[100][8]; int n = 0; try { String sql = \"select * FROM 图书借阅 where 图书编号=?\"; PreparedStatement ps = ct.prepareStatement(sql); ps.setString(1, bookNumber); rs = ps.executeQuery(); while (rs.next()) { ob[n][0] = rs.getString(\"读者编号\"); String s = dateCal.borrowTimeInterface(Long.parseLong(rs .getString(\"借阅时间\"))); ob[n][1] = s; long re = Long.parseLong(rs.getString(\"应还时间\")); s = dateCal.borrowTimeInterface(re); ob[n][2] = s; long re1 = System.currentTimeMillis(); if (re1 > re) { ob[n][3] = Long.toString(((re1 - re) / 86400000)+1) + \" Days\"; } else { 页脚内容 课 程 设 计 } } } ob[n][3] = \"NOT\"; n++; } catch (Exception e) { } return ob; System.out.println(e); public int deleteBookCheck(String bookNumber) { int i = 0; ArrayList String sql = \"select * FROM 图书借阅\"; PreparedStatement ps = ct.prepareStatement(sql); // ps.setString(1, bookNumber); rs = ps.executeQuery(); int count = 0; while (rs.next()) { } for (; count > 0; count--) { 页脚内容 String s = rs.getString(\"图书编号\"); strArray.add(s); count++; 课 程 设 计 } } if (strArray.get(count - 1).equals(bookNumber)) { } i++; } catch (Exception e) { } return i; System.out.println(e); public int deleteReaderCheck(String readerNumber) { int i = 0; ArrayList String sql = \"select * FROM 图书借阅\"; PreparedStatement ps = ct.prepareStatement(sql); // ps.setString(1, bookNumber); rs = ps.executeQuery(); int count = 0; while (rs.next()) { } for (; count > 0; count--) { 页脚内容 String s = rs.getString(\"读者编号\"); strArray.add(s); count++; 课 程 设 计 } } } if (strArray.get(count - 1).equals(readerNumber)) { } i++; } catch (Exception e) { } return i; System.out.println(e); 十、总结 经过这段时间的努力基本完成了图书管理系统。同时通过这几天的程序及报告编写,把学过的Java知识运用到了实践。我也发现了自己的很多不足,自己知识的很多漏洞,看到了自己的实践经验还是比较缺乏,理论联系实际的能力还是比较脆弱。尤其是编写大型的程序所要拥有的知识和技能比较缺乏。程序编好了,还要经过调试和修改,这步也很关键,好的程序是经过了无数次的修改和调试才产生的。我们的程序基本上能够满足要求,但还有一些地方需要改进,在今后我们 页脚内容 课 程 设 计 应该在多看书的同时还要加强实践的练习。才能进一步提高自己的编程能力。 参考文献 [1] 王珊,萨师煊.《数据库系统概论》.高等教育出版社,2006.5 [2] Y.Danniel Liang.《Java语言程序设计-基础篇》.机械工业出版社,2011.5 [3]张峋,杨三成.《JSP与JDBC应用详解》.中国铁道出版社,2010.11 页脚内容 因篇幅问题不能全部显示,请点此查看更多更全内容