图书管理系统java代码

合集下载

基于java的图书馆管理系统毕业设计(含源文件)

基于java的图书馆管理系统毕业设计(含源文件)

毕业论文题目:图书馆集成系统目录前言第一章绪论第一节设计初衷第二节设计任务第三节 JAVA介绍第四节编程运行环境第五节系统简介第二章系统实现第一节系统设计流程第二节系统实现过程第三章结束语第四章附注谢辞参考文献毕业论文_____图书馆集成管理系统前言随着电脑技术的发展以及电脑网络的逐渐普及,英特网成为人们查找信息的重要场所。

二十一世纪是信息的时代,所以信息的交换和信息流通显的特别重要。

因此、图书馆使用电脑来管理成为必然。

第二章绪论第一节设计初衷第二节设计任务第三节 JAVA介绍JAVA是INTERNET开发的一个强大的工具,它是一个C++的简化版本。

JAVA是一门"简单的、面向对象的、强类型的、编译型的、结构无关的、多线程(multi-threaded)的、垃圾自动收集的、健壮的、安全的、可扩展的语言。

本系统使用的是美国微软公司的MICROSOFT VISUAL J++6.0。

MICROSOFT VISUAL J++6.0是用于JAVA编程的WINDOWS集成环境。

在Visual J++中,用户可以创建、修改、编译、运行、调试和封装应用程序,所有这些操作都在单一的环境中进行。

介绍Java的Windows基础类〔WFC〕,这个新的应用程序框架访问Microsoft Windows API,允许用户用Java编成语言编写全特性的Winndows应用程序。

WFC 也包装在中执行的动态HTML 对象模型,这就让用户能够动态地操作在客户和服务器两者上的HTML。

用户可以很方便地在Visual J++内访问数据。

通过添加WFC 数据控件在Forms Designer中的窗体上,可以快速配置数据检索和显示的方式。

Visual J++通过ActiveX Data Object(ADO, ActiveX数据对象)控件来访问数据,这是用于WFC应用程序的数据编程模块。

ADO对象的内核包含Connection(连接)、Command 〔命令〕和Recordset〔记录集〕对象,利用它们,可以连接到数据库和检索记录集。

javaswing图书管理系统实报告

javaswing图书管理系统实报告

四、实验方法和步骤
实验方法:
1、本系统是基于Java Swing+MySQL实现的图书管理系统。

2、采用Java Swing作为UI界面
3、MySQL数据库作为存储
4、JDBC原生方法操作
(封装了公共的增删改查方法,见src.model.access.Connect.java)
5、采用MVC模式分为Model层、View层、Controller层
6、采用了MD5进行密码加密
实验步骤:
1、需求分析
2、概念结构,绘制E-R图
3、逻辑结构设计:将E-R图转化为等价的关系模式
4、物理结构设计:数据库表的基本结构
5、功能实现
五、实验结果(截图)
1、登录界面
2、普通用户登录界面
3、管理员登录界面
4用户界面功能分别是
图书查询借阅、借阅归还信息、个人信息管理4.1借阅
4.3查询
4.4借阅信息
4.5归还
4.6个人信息管理4.7修改个人信息
4.8修改密码
5.登录界面功能5.1注册功能
6.忘记密码功能
7.管理端功能
图书信息管理、图书种类管理、读者类型管理、图书借阅信息、超级用户7.1界面
7.2添加图书
7.3删除图书
7.4修改图书
7.5图书类型管理7.6读者信息管理历史借阅信息
7.7超级管理员界面修改个人信息
修改个人密码
7.8超级管理员验证查询管理员信息
新增管理员
删除管理员
修改该管理员信息。

java实训报告--图书管理系统

java实训报告--图书管理系统

java实训报告--图书管理系统一、项目介绍本项目是一个基于Java的图书管理系统,主要包括图书类别管理、图书信息管理、读者信息管理以及借阅和归还管理等模块。

实现了对图书馆资源的有效管理,提高了图书馆工作效率,满足了读者的需求。

二、需求分析1.用户权限分级实现用户登陆验证,分为管理员和普通用户两类,管理员有图书信息、读者信息、借阅还书和系统管理四种权限,普通用户只有查询和借还书的权限。

2.图书管理管理员可以对图书进行分类管理、添加书目、查看书目、修改和删除图书信息等操作。

3.读者管理管理员可以对读者进行添加、查看、修改和删除读者信息等操作。

普通用户只能查询自己的借书信息和还书日期。

4.借阅还书管理管理员可以对图书的借阅还书进行处理和管理,包括借书和还书操作,超期处理以及还书日期提醒等。

5.系统管理管理员可以对图书馆系统进行管理,包括用户管理、修改密码等操作。

三、设计实现1.数据库设计采用MySQL数据库进行数据存储,主要包括用户表、图书分类表、图书信息表、读者信息表、借阅信息表等。

2.界面设计采用Swing框架实现界面设计,UI界面简洁美观,与用户交互友好。

3.代码实现代码主要采用Java语言实现,采用MVC模式,将业务和UI 进行分离,提高了灵活性和可维护性。

四、实现效果本系统实现了对图书馆资源的有效管理,对管理员可以方便地进行操作,对普通用户可以快速方便地查询和借阅图书。

五、总结通过该项目的实现,使我深入学习了Java语言的面向对象编程、MVC模式、MySQL数据库的使用、Swing界面设计等技术,并深刻体会到了软件开发的需求分析、系统设计、编码实现、测试等基本流程。

同时,也感受到了信息化技术在实际工作中所带来的效率和便捷。

图书管理系统需求分析报告附有java代码

图书管理系统需求分析报告附有java代码

目录一.概述1.编写目的2。

项目背景3。

定义4。

参考资料5.开发环境二.需求分析1。

问题提出2。

系统的业务功能分析3。

需完成的功能三.系统需求说明1。

对功能的规定2。

对性能的规定3。

输入输出要求四.新系统的逻辑模型1。

图书馆组织机构分析2。

系统功能结构图3。

业务流程图4.数据流程图5.数据字典一.概述1、编写目的按照关系型数据库的基本原理,综合运用所学的知识,以小组为单位,设计开发一个小型的图书管理系统。

通过对一个实际问题的分析、设计与实现,将原理与应用相结合,使学生学会如何把书本上学到的知识用于解决实际问题,培养学生的动手能力;另一方面,使学生能深入理解和灵活掌握教学内容2、项目背景数据处理手工操作,工作量大,出错率高,出错后不易更改。

图书馆采取手工方式对图书借阅情况进行人工管理,由于信息比较多,图书借阅信息的管理工作混乱而又复杂;一般借阅情况是记录在借书证上,图书的数目和内容记录在文件中,图书馆的工作人员和管理员也只是当时对它比较清楚,时间一长,如再要进行查询,就得在众多的资料中翻阅、查找了。

造成查询费时、费力.如要对很长时间以前的图书进行更改就更加困难了。

.a。

待开发的软件系统的名称是《图书管理系统》b。

本软件适用于教育界,他是比较完善的系统管理软件,对图书馆的书籍、读者资料、借还书等可以进行方便的管理。

C。

开发员:蔚奇秀,曹海花,李小峰,祁乐3、定义数据流程图(DFD):为描述软件系统中的信息流提供了一个图形方法。

箭头代表数据流,方框代表数据的源点或终点,圆框代表数据流的交换,双杠代表数据存储的地方.数据字典是对数据流程图中的数据,变换等进行精确的定义.4、参考资料1.萨师煊、王珊《数据库系统概论》高等教育出版社2000。

22.俞盘祥、沈金发《数据库系统原理》清华大学出版社2000。

63.王珊、陈红《数据库系统原理教程》清华大学出版社1998.74.施伯乐、丁宝康《数据库系统教程》高等教育出版社1999.125、开发环境WindowXP,/7 Microsoft Visual C++, SQLSerevr2000.一、需求分析1、问题的提出:图书馆作为一种信息资源的集散地,图书和用户借阅资料繁多,包含很多的信息数据的管理,现今,有很多的图书馆都是初步开始使用,甚至尚未使用计算机进行信息管理。

图书馆管理系统(JavaWeb)

图书馆管理系统(JavaWeb)

图书馆管理系统(JavaWeb)图书馆管理系统(Java Web)概述基于Spring + Spring MVC + MyBatis的图书馆管理系统,使⽤Maven进⾏包管理。

主要功能包括:图书查询、图书管理、图书编辑、读者管理、图书的借阅与归还以及借还⽇志记录等。

项⽬演⽰<——点击跳转<——点击跳转<——点击跳转<——点击跳转环境配置需要提前配置好Maven环境,数据库为MySql,在src/main/resources/db.properties中修改MySql⽤户名和密码。

数据库脚本在library.sql中,可⾃动建库。

使⽤mvn jetty:run可快速搭建。

特别注意:如果要搭⼊服务器中使⽤,⽤tomcat跑需要将项⽬打包⼊tomcat中的root⽂件夹使⽤,因为项⽬设计时,⽤的jetty,所有jsp⽂件路径写的都是相对路径。

概念设计⽤户分为两类:读者、图书馆管理员。

图书馆管理员可以修改读者信息,修改书⽬信息,查看所有借还⽇志等;读者仅可以修改个⼈信息、借阅或归还书籍和查看⾃⼰的借还⽇志。

数据库E-R图逻辑设计共有6个表:1. 图书书⽬表book_info名类型长度⼩数点NULL⽤途键book_id bigint200否图书号✔name varchar200否书名author varchar150否作者publish varchar200否出版社ISBN varchar150否标准书号introduction text00是简介language varchar40否语⾔price decimal102否价格pub_date date00否出版时间class_id int110是分类号number int110是剩余数量2. 数据库管理员表admin名类型长度⼩数点NULL⽤途键admin_id bigint200否账号✔password varchar150否密码username varchar150是⽤户名3. 图书分类表class_info名类型长度⼩数点NULL⽤途键class_id int110否类别号✔class_name varchar150否类别名4. 借阅信息表lend_list名类型长度⼩数点NULL⽤途键ser_num bigint200否流⽔号✔book_id bigint200否图书号reader_id bigint200否读者证号lend_date date00是借出⽇期back_date date00是归还⽇期5. 借阅卡信息表reader_card名类型长度⼩数点NULL⽤途键reader_id bigint200否读者证号✔password varchar150否密码username varchar150是⽤户名6. 读者信息表reader_info名类型长度⼩数点NULL⽤途键reader_id bigint200否读者证号✔name varchar100否姓名sex varchar20否性别birth date00否⽣⽇address varchar500否地址phone varchar150否电话功能展⽰1. ⾸页登陆管理者账号:123456/123456(见数据库admin表)读者账号:10000/123456()见数据库reader_card表2. 管理员系统⽤登陆进⼊2.1 图书管理2.2 图书详情2.3 读者管理2.4 借还管理3. 读者系统3.1 查看全部图书3.2 个⼈信息查看,可以修个个⼈信息3.3 个⼈借阅情况查看。

javase综合案例

javase综合案例

javase综合案例综合案例:图书管理系统一、引言图书管理系统是一种用于管理与存储图书信息的软件系统。

该系统可以实现对图书的借阅、归还、续借、借阅记录查询等功能,方便图书馆管理人员进行图书管理工作。

本文将介绍一个基于JavaSE的图书管理系统的设计与实现。

二、需求分析1. 系统应具备管理员和读者两种角色,管理员可以进行图书管理操作,读者可以进行借阅和归还操作。

2. 系统应提供图书的添加、删除、修改和查询功能,管理员可通过图书的书名、作者等信息快速检索图书。

3. 系统应提供读者的注册、注销和查询功能,读者可以通过借阅号和密码登录系统。

4. 系统应记录借阅记录,包括借阅日期、归还日期和借阅状态等信息。

5. 系统应提供图书的借阅、归还和续借功能,借阅时应检查图书库存和读者的借书上限。

6. 系统应提供借阅记录的查询功能,管理员可按照读者或图书进行查询。

7. 系统应具备良好的用户界面,方便操作和使用。

三、系统设计根据需求分析,系统的核心功能包括图书管理、读者管理和借阅管理。

因此,可以设计三个核心类:Book、Reader和BorrowRecord。

1. Book类Book类用于存储图书信息,包括书名、作者、出版社、出版日期、图书编号和库存数量等属性。

该类还提供图书的添加、删除和修改方法,以及根据书名、作者等信息进行查询的方法。

2. Reader类Reader类用于存储读者信息,包括借阅号、姓名、性别、年龄和借书上限等属性。

该类还提供读者的注册、注销和查询方法,以及读者登录系统的方法。

3. BorrowRecord类BorrowRecord类用于存储借阅记录,包括借阅日期、归还日期、借阅状态、借阅图书和借阅读者等属性。

该类还提供借书、还书和续借的方法,以及查询借阅记录的方法。

四、系统实现根据系统设计,可以编写相关的Java类文件来实现图书管理系统。

以下是部分代码示例:Book.java:```javapublic class Book {private String name;private String author;private String publisher;private String publicationDate;private int stock;// 构造方法// 添加图书public void addBook() {// 添加图书逻辑}// 删除图书public void deleteBook() {// 删除图书逻辑}// 修改图书public void modifyBook() {// 修改图书逻辑}// 根据书名和作者查询图书public void searchBook(String name, String author) { // 查询图书逻辑}}Reader.java:```javapublic class Reader {private String name;private String gender;private int age;private int borrowLimit;// 构造方法// 注册读者public void register() {// 注册逻辑}// 注销读者public void cancel() {// 注销逻辑}// 查询读者信息public void searchReader() {// 查询读者逻辑}// 读者登录public void login(String borrowId, String password) { // 登录逻辑}}BorrowRecord.java:```javapublic class BorrowRecord {private Date borrowDate;private Date returnDate;private boolean borrowStatus;private Book book;private Reader reader;// 构造方法// 借书public void borrow(Book book, Reader reader) {// 借书逻辑}// 还书public void returnBook(Book book, Reader reader) { // 还书逻辑}// 续借public void renew(Book book, Reader reader) {// 续借逻辑}// 查询借阅记录public void searchRecord(Book book, Reader reader) { // 查询记录逻辑}}```以上仅为图书管理系统的基本功能和类的设计示例,实际开发中还需进一步完善和优化。

java实现图书馆管理系统

java实现图书馆管理系统

java实现图书馆管理系统本⽂实例为⼤家分享了java实现图书馆管理系统的具体代码,供⼤家参考,具体内容如下思路:所有包都在book_manage包⾥利⽤⾯向对象的多态特性去除了很多if-else的判断,不同的⼦类在⽗类所对应的⽅法不同。

1.⾸先建⽴⼀个book包包⾥⾯有2个类,⼀个是Book,这个类⾥⾯包含⼀本书的全部信息另外⼀个类是BookList,这个类是⽤来管理每⼀个书,通过这个类来寻找每⼀本书。

private Book[] books = new Book[100];Book数组⾥⾯存放所有的书。

2.再建⽴⼀个包Operation 这个类⾥⾯有⼀个OI接⼝,通过对接⼝⾥⾯的Work⽅法重写,来实现管理员⾝份和普通⽤户⾝份的不同操作。

3.最后建⽴⼀个User包,⾥⾯有三个类,User,Admin,NormalUserAdmin和NormalUser都继承⾃User.User⾥秒你有⼀个数组protected IO[] operation;这个数组⾥⾯包含了⽤户或者管理员所具备的操作。

通过对数组的索引来确定具体需要调⽤的操作⽅法。

下⾯来看看代码吧:book包Book类package book_manager.book;public class Book {private String name;private String id;private String author;private int price;private String type;private boolean isBorrow;public Book(String name, String id, String author, int price,String type, boolean isBorrow) { = name;this.id = id;this.author = author;this.price = price;this.type = type;this.isBorrow = isBorrow;}@Override //Object中内置的类,⽤来格式化打印book的信息public String toString() {return "Book{" +"name='" + name + '\'' +", id='" + id + '\'' +", author='" + author + '\'' +", price=" + price +", type='" + type + '\'' +", isBorrow=" + isBorrow +'}';}public String getName(){return name;}public boolean isBorrow(){public void setBorrow(boolean bool){this.isBorrow=bool;}public String getId(){return id;}}BookList类package book_manager.book;import java.util.Arrays;public class BookList {private Book[] books = new Book[100];private int size;public BookList(){books[0] = new Book("⾦瓶梅","001", "兰陵笑笑⽣", 100,"古典名著", false);books[1] = new Book("⽔浒传","002", "施耐庵", 100,"古典名著", false);books[2] = new Book("西游记","003", "吴承恩", 100,"古典名著", false);size = 3;}public int getSize(){return size;}public void setBooks(int index,Book book){ books[index]=book;}public void setSize(int size){this.size=size;}public Book getBook(int index){return books[index];}}Operation包:ADD类package book_manager.Operation;import book_manager.book.*;import java.util.Scanner;public class ADD implements IO{@Overridepublic void work(BookList bookList) {Scanner scanner = new Scanner(System.in); System.out.println("请输⼊书名");String name =scanner.next();System.out.println("请输⼊序号");String id = scanner.next();System.out.println("请输⼊作者");String author =scanner.next();System.out.println("请输⼊价格");int price = scanner.nextInt();System.out.println("请输⼊类型");String type = scanner.next();bookList.setBooks(bookList.getSize(),book);bookList.setSize(bookList.getSize()+1);System.out.println("添加成功");}}Borrow类package book_manager.Operation;import book_manager.book.Book;import book_manager.book.BookList;import java.util.Scanner;public class Borrow implements IO{@Overridepublic void work(BookList bookList) {int i=0;int flag=0;Scanner scan = new Scanner(System.in);System.out.println("请输⼊需要借阅的书名");String name = scan.next();for(;i<bookList.getSize();i++){if(name.equals(bookList.getBook(i).getName())){if(bookList.getBook(i).isBorrow()==false){System.out.println("借阅成功");flag=1;bookList.getBook(i).setBorrow(true);}}}if(flag==0){System.out.println("不好意思,借阅失败");}}}Delete类package book_manager.Operation;import book_manager.book.BookList;import java.util.Scanner;public class Delete implements IO{public void work(BookList bookList){Scanner scanner = new Scanner(System.in);System.out.println("请输⼊想要删除的编号");String id = scanner.next();for(int i=0;i<bookList.getSize();i++){if(bookList.getBook(i).getId().equals(id)){bookList.setBooks(i,bookList.getBook(bookList.getSize())); bookList.setSize(bookList.getSize()-1);System.out.println("删除成功");}else{System.out.println("删除失败");}}}}Exit类package book_manager.Operation;import book_manager.book.BookList;public class Exit implements IO{public void work(BookList bookList) {System.out.println("退出成功");System.exit(0);}}Find类package book_manager.Operation;import book_manager.book.BookList;import java.util.Scanner;public class Find implements IO{@Overridepublic void work(BookList bookList) {int i=0;int count=0;Scanner scan = new Scanner(System.in);System.out.println("请输⼊需要查找的书名");String name = scan.next();for(;i<bookList.getSize();i++){if(name.equals(bookList.getBook(i).getName())){ count++;}}if(count==0){System.out.println("不好意思,没有找到"); }else{System.out.println("找到了,共计"+count+"本"); }}}IO接⼝package book_manager.Operation;import book_manager.book.BookList;public interface IO {abstract public void work(BookList bookList);}PrintAll类package book_manager.Operation;import book_manager.book.BookList;public class PrintAll implements IO{@Overridepublic void work(BookList bookList) {for(int i=0;i<bookList.getSize();i++){System.out.println(bookList.getBook(i));}}}Return类package book_manager.Operation;import book_manager.book.BookList;import java.util.Scanner;public class Return implements IO{@Overridepublic void work(BookList bookList) {int i=0;Scanner scan = new Scanner(System.in);System.out.println("请输⼊需要归还的ID");String id = scan.next();for(;i<bookList.getSize();i++){if(id.equals(bookList.getBook(i).getId())){if(bookList.getBook(i).isBorrow()==true){System.out.println("归还成功");bookList.getBook(i).setBorrow(false);flag=1;}else{System.out.println("归还失败");}}}if(flag==0){System.out.println("不好意思,没有此书");}}}user包:User类package book_er;import book_manager.Operation.*;import book_manager.Operation.IO;import book_manager.book.BookList;abstract public class User {String name;protected IO[] operation;public User(String name){=name;}abstract public int menu();//该⽅法被重写public void doOperation(int choice, BookList bookList) { operation[choice].work(bookList);}}Admin类package book_er;import book_manager.Operation.*;import java.util.Scanner;public class Admin extends User{public Admin(String name){super(name);operation=new IO[]{new Exit(),new Find(),new ADD(),new Delete(),new PrintAll(),};}public int menu() {System.out.println("============");System.out.println("hello " + name);System.out.println("1. 查找书籍");System.out.println("4. 打印所有信息");System.out.println("0. 退出");System.out.println("============");System.out.println("请输⼊您的选择: ");Scanner scanner = new Scanner(System.in);int choice = scanner.nextInt();return choice;}}NormalUserpackage book_er;import book_manager.Operation.*;import java.util.Scanner;public class NormalUser extends User{public NormalUser(String name){super(name);operation=new IO[]{new Exit(),new Find(),new Borrow(),new Return(),new PrintAll()};}public int menu() {System.out.println("============");System.out.println("hello " + name);System.out.println("1. 查找图书");System.out.println("2. 借阅图书");System.out.println("3. 归还图书");System.out.println("4. 查看全部书籍");System.out.println("0. 退出");System.out.println("============");System.out.println("请输⼊您的选择: ");Scanner scanner = new Scanner(System.in);int choice = scanner.nextInt();// close 本质上是在关闭 System.in// 由于后⾯还需要⽤到 System.in, 此处不能盲⽬关闭. // scanner.close();return choice;}}最后还有⼀个Test类,⾥⾯放了main函数package book_manager;import book_manager.book.BookList;import book_er.Admin;import book_er.NormalUser;import book_er;import java.util.Scanner;public class Test {public static void main(String[] args) {BookList list = new BookList();User user = login();//通过不同的choice和⾝份调⽤不同的Operation⽅法 while(true){int choice = user.menu();user.doOperation(choice, list);}}public static User login(){Scanner scanner = new Scanner(System.in);System.out.println("请输⼊你的姓名");System.out.println("请输⼊你的⾝份");System.out.println("1.普通⽤户 2.管理员");int role= scanner.nextInt();if(role==1){return new NormalUser(name);}else{return new Admin(name);}}}更多学习资料请关注专题《》。

图书管理系统源码(java实现)

图书管理系统源码(java实现)

【图书管理系统】【MainPro包】1.系统登录页面public class Login extends Frame {private static final long serialVersionUID = -1758475247807861408L;TextField text_user;TextField text_pass;public Login() {1 this.setTitle("登录");this.setLayout(null);//默认流式布局this.setSize(260, 170);/* 定义标签与文本框*/Label lbUser = new Label("用户名:");text_user = new TextField();Label lbPass = new Label("密码:");text_pass = new TextField();Button btn_ok = new Button("确定");Button btn_cancel = new Button("取消");lbUser.setBounds(40, 53, 60, 20);//x,y,width,heightlbPass.setBounds(40, 83, 60, 20);text_user.setBounds(100, 50, 120, 20);text_pass.setBounds(100, 80, 120, 20);btn_ok.setBounds(45, 120, 80, 25); // 确定按钮btn_cancel.setBounds(135, 120, 80, 25); // 取消按钮/* 添加标签与文本框*/add(lbUser);add(lbPass);add(text_user);add(text_pass);add(btn_ok);add(btn_cancel);setLocationRelativeTo(null); // 使窗体在屏幕上居中放置this.setVisible(true); // 使窗体可见btn_ok.addActionListener((new ActionListener() {public void actionPerformed(ActionEvent e) {btn_okActionPerformed(e);//自定义确定按钮触发的实施过程}}));btn_cancel.addActionListener((new ActionListener() {public void actionPerformed(ActionEvent e) {DbOp.Close(); // 关闭数据库System.exit(0);}}));this.addWindowListener(new WindowAdapter() {/* 关闭窗口*/// 重写windowClosing()方法public void windowClosing(WindowEvent e) {DbOp.Close(); // 关闭数据库System.exit(0);} }); }public void btn_okActionPerformed(ActionEvent e) {String user = text_user.getText();String pass = text_pass.getText();String is_admin;// 如果用户名或密码任一为空,则终止后续操作if (user.equals("")||pass.equals("")) {JOptionPane.showMessageDialog(null, "用户名或密码不能为空!");return;}try {// 核对用户名和密码String sql = "select * from user where username=" + "'" + user + "' and password=" + "'" + pass + "'";ResultSet rs = DbOp.executeQuery(sql);// 如果此用户存在,则记录其状态(否:不是管理员,是:是管理员)if (rs.next()) {is_admin = rs.getString("is_admin");} else {JOptionPane.showMessageDialog(null, "用户名或密码不正确!");return;}GlobalVar.login_user = user; // 记录登录的用户名ShowMain show = new ShowMain(); // 调用主程序// 只有管理员才能使用"基础管理"和"借阅管理"菜单show.setRights(is_admin);// 释放窗体及其全部组件的屏幕资源,即使释放登录窗体dispose(); // 释放当前窗体} catch (SQLException e1) {JOptionPane.showMessageDialog(null, "用户数据库有误!");}}}2.系统首页页面public class ShowMain extends Frame {private static final long serialVersionUID = 5003296786441785470L;MenuBar menuBar;Menu jcwh, jcwh_book, jcwh_reader;//基础维护:图书维护、读者维护Menu jywh, cxgl, xtgl;//借阅维护、查询管理、系统管理MenuItemjcwh_book_add,jcwh_book_update,jcwh_book_delete,jcwh_reader_add,jcwh_reader_update,jcwh_reader_delete;MenuItem jywh_borrow, jywh_back;MenuItem cxgl_book, cxgl_reader;MenuItem xtgl_update_pass, xtgl_exit;public void setRights(String rights) {// 如果不是管理员,则禁止用户维护图书信息和读者信息以及禁止进行借阅管理,即只能查询if (rights.equals("否")) {jywh.setEnabled(false);jcwh.setEnabled(false);}}public ShowMain() {setTitle("图书管理系统");setLayout(new BorderLayout());setSize(640, 480);menuBar = new MenuBar();jcwh = new Menu("基础维护");// 基础维护菜单jcwh_book = new Menu("图书维护");// 图书维护菜单jcwh_book_add = new MenuItem("添加");// 添加图书菜单jcwh_book_update = new MenuItem("修改");// 修改图书菜单jcwh_book_delete = new MenuItem("删除");// 删除图书菜单jcwh_reader = new Menu("读者维护");// 读者维护菜单jcwh_reader_add = new MenuItem("添加读者");// 添加读者菜单jcwh_reader_update = new MenuItem("修改读者");jcwh_reader_delete = new MenuItem("删除读者");jywh = new Menu("借阅管理");jywh_borrow = new MenuItem("借书管理");jywh_back = new MenuItem("还书管理");cxgl = new Menu("查询管理");cxgl_book = new MenuItem("图书查询");cxgl_reader = new MenuItem("读者查询");xtgl = new Menu("系统管理");xtgl_update_pass = new MenuItem("修改密码");xtgl_exit = new MenuItem("退出系统");// 添加图书菜单jcwh_book.add(jcwh_book_add);jcwh_book.add(jcwh_book_update);jcwh_book.add(jcwh_book_delete);jcwh.add(jcwh_book);jcwh_reader.add(jcwh_reader_add);jcwh_reader.add(jcwh_reader_update);jcwh_reader.add(jcwh_reader_delete);jcwh.add(jcwh_reader);jywh.add(jywh_borrow);jywh.add(jywh_back);cxgl.add(cxgl_book);cxgl.add(cxgl_reader);xtgl.add(xtgl_update_pass);xtgl.add(xtgl_exit);menuBar.add(jcwh);menuBar.add(jywh);menuBar.add(cxgl);menuBar.add(xtgl);setMenuBar(menuBar);setLocationRelativeTo(null); // 使窗体在屏幕上居中放置setVisible(true); // 使窗体可见jcwh_book_add.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {new BookManeger("save");} });jcwh_book_update.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {new BookManeger("update");} });jcwh_book_delete.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {new BookManeger("delete");} });jcwh_reader_add.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {new ReaderManeger("save");} });jcwh_reader_update.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {new ReaderManeger("update");} });jcwh_reader_delete.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {new ReaderManeger("delete");} });jywh_borrow.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {new Borrow();} });jywh_back.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {new Back();} });cxgl_book.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {new BookQuery();} });cxgl_reader.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {new ReaderQuery();} });xtgl_update_pass.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {new UpdatePassword();} });xtgl_exit.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {DbOp.Close(); // 关闭数据库System.exit(0);}});this.addWindowListener(new WindowAdapter() {/* 关闭窗口*/// 重写windowClosing()方法public void windowClosing(WindowEvent e) {DbOp.Close(); // 关闭数据库System.exit(0);}});}}3.图书管理public class BookManeger extends JFrame {private static final long serialVersionUID = 377287301994613384L;private Label lbbookid_c = new Label("图书编号");private TextField tf_bookid_c = new TextField();private Label lbbookid = new Label("图书编号");private TextField tf_bookid = new TextField();private Label lbbookname = new Label("图书名称");private TextField tf_bookname = new TextField();private Label lbbooktype = new Label("图书类别");private Choice tf_booktype = new Choice();private Label lbauthor = new Label("作者");private TextField tf_author = new TextField();private Label lbtranslator = new Label("译者");private TextField tf_translator = new TextField();private Label lbpublisher = new Label("出版社");private TextField tf_publisher = new TextField();private Label lbpublish_time = new Label("出版时间");private TextField tf_publish_time = new TextField();private Label lbprice = new Label("定价");private TextField tf_price = new TextField();private Label lbstock = new Label("库存数量");private TextField tf_stock = new TextField();private Button queryBtn = new Button("查询");private Button saveBtn = new Button("保存");private Button closeBtn = new Button("关闭");private String optionStr;BookManeger(String str) {optionStr = str;ggFrame(optionStr);saveBtn.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {HashMap<String, Object> map = new HashMap<String, Object>();map.put("bookid", tf_bookid);map.put("bookname", tf_bookname);map.put("booktype", tf_booktype);map.put("author", tf_author);map.put("translator", tf_translator);map.put("publisher", tf_publisher);map.put("publish_time", tf_publish_time);map.put("price", tf_price);map.put("stock", tf_stock);int i ;if(optionStr.equals("delete")){i = Jcwh.btn_delActionPerformed(e, map);}else{i = Jcwh.btn_saveActionPerformed(e, map,optionStr);}if (i == 1) {String showInfo = "";if(optionStr.equals("save")){showInfo = "图书添加成功!";}else if(optionStr.equals("update")){showInfo = "图书修改成功!";}else if(optionStr.equals("delete")){showInfo = "图书删除成功!";}JOptionPane.showMessageDialog(null, showInfo);// 清空全部文本框clearAllTextfield();}}});closeBtn.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {dispose(); // 释放当前窗体}});/* 关闭窗口*/this.addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) { // 关闭当前窗口dispose(); // 释放当前窗体}});}private void ggFrame(String str) {setLayout(null);setSize(500, 320);lbbookid.setBounds(50, 40, 50, 20); // 图书编号tf_bookid.setBounds(110, 40, 100, 20);lbbookname.setBounds(240, 40, 50, 20); // 图书名称tf_bookname.setBounds(300, 40, 100, 20);lbbooktype.setBounds(50, 80, 50, 20); // 图书类别tf_booktype.setBounds(110, 80, 100, 20);tf_booktype.add("科技");tf_booktype.add("文学");tf_booktype.add("社科");tf_booktype.add("其他");lbauthor.setBounds(240, 80, 50, 20); // 作者tf_author.setBounds(300, 80, 100, 20);lbtranslator.setBounds(50, 120, 50, 20); // 设置译者tf_translator.setBounds(110, 120, 100, 20);lbpublisher.setBounds(240, 120, 50, 20); // 出版社tf_publisher.setBounds(300, 120, 100, 20);lbpublish_time.setBounds(50, 160, 50, 20); // 出版时间tf_publish_time.setBounds(110, 160, 100, 20);lbprice.setBounds(240, 160, 50, 20); // 定价tf_price.setBounds(300, 160, 100, 20);lbstock.setBounds(50, 200, 50, 20); // 库存数量tf_stock.setBounds(110, 200, 100, 20);saveBtn.setBounds(150, 240, 80, 25); // 保存按钮closeBtn.setBounds(280, 240, 80, 25);// 关闭按钮if(str.equals("save")){setTitle("添加图书");}else if(str.equals("update")){setTitle("修改图书");lbbookid_c.setBounds(100, 10, 50, 20); // 图书编号tf_bookid_c.setBounds(160, 10, 100, 20);tf_bookid.setEditable(false);//修改的图书信息中id不可以修改queryBtn.setBounds(280, 10, 80, 20); // 查询按钮add(lbbookid_c);add(tf_bookid_c);add(queryBtn);queryBtn.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {HashMap<String, Object> map = new HashMap<String, Object>();map.put("bookid", tf_bookid_c);Book book = (Book)Jcwh.btn_queryActionPerformed(e,map).get("book");if(book!=null){tf_bookid.setText(book.getId());tf_bookname.setText(book.getBookname());// 将Choice的选定项设置为其名称等于指定字符串的项tf_booktype.select(book.getBooktype());tf_author.setText(book.getAuthor());tf_translator.setText(book.getTranslator());tf_publisher.setText(book.getPublisher());tf_publish_time.setText(book.getPublish_time().toString());tf_price.setText(String.valueOf(book.getPrice()));tf_stock.setText(String.valueOf(book.getStock()));}}});saveBtn.setLabel("修改");//将按钮显示文字修改成“修改”}else if(str.equals("delete")){setTitle("删除图书");lbbookid_c.setBounds(100, 10, 50, 20); // 图书编号tf_bookid_c.setBounds(160, 10, 100, 20);tf_bookid.setEditable(false);//修改的图书信息中id不可以修改queryBtn.setBounds(280, 10, 80, 20); // 查询按钮add(lbbookid_c);add(tf_bookid_c);add(queryBtn);queryBtn.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {HashMap<String, Object> map = new HashMap<String, Object>();map.put("bookid", tf_bookid_c);Book book = (Book)Jcwh.btn_queryActionPerformed(e,map).get("book");if(book!=null){tf_bookid.setText(book.getId());tf_bookname.setText(book.getBookname());// 将Choice的选定项设置为其名称等于指定字符串的项tf_booktype.select(book.getBooktype());tf_author.setText(book.getAuthor());tf_translator.setText(book.getTranslator());tf_publisher.setText(book.getPublisher());tf_publish_time.setText(book.getPublish_time().toString());tf_price.setText(String.valueOf(book.getPrice()));tf_stock.setText(String.valueOf(book.getStock()));}}});saveBtn.setLabel("删除");//将按钮显示文字修改成“删除”}add(lbbookid);add(tf_bookid);add(lbbookname);add(tf_bookname);add(lbbooktype);add(tf_booktype);add(lbauthor);add(tf_author);add(lbtranslator);add(tf_translator);add(lbpublisher);add(tf_publisher);add(lbpublish_time);add(tf_publish_time);add(lbprice);add(tf_price);add(lbstock);add(tf_stock);add(saveBtn);add(closeBtn);setLocationRelativeTo(null); // 使窗体在屏幕上居中放置setVisible(true); // 使窗体可见}private void clearAllTextfield() {tf_bookid.setText("");tf_bookname.setText("");tf_author.setText("");tf_translator.setText("");tf_publisher.setText("");tf_publish_time.setText("");tf_price.setText("");tf_stock.setText("");}}4.读者管理public class ReaderManeger extends JFrame {private static final long serialVersionUID = -2399939451497711745L;Label lbreaderid_c = new Label("读者编号");TextField tf_readerid_c = new TextField();Label lbreaderid = new Label("读者编号");TextField tf_readerid = new TextField();Label lbreadername = new Label("读者姓名");TextField tf_readername = new TextField();Label lbreadertype = new Label("读者类别");Choice tf_readertype = new Choice();Label lbsex = new Label("性别");Choice tf_sex = new Choice();Label lbmax_num = new Label("可借数量");TextField tf_max_num = new TextField();Label lbdays_num = new Label("可借天数");TextField tf_days_num = new TextField();Button queryBtn = new Button("查询");Button saveBtn = new Button("保存");Button closeBtn = new Button("关闭");private String optionStr;//保存、修改、删除ReaderManeger(String str){optionStr = str;ggFrame(optionStr);saveBtn.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {HashMap<String, Object> map = new HashMap<String, Object>();map.put("readerid", tf_readerid);map.put("readername", tf_readername);map.put("readertype", tf_readertype);map.put("sex", tf_sex);map.put("days_num", tf_days_num);map.put("max_num", tf_max_num);int i ;if(optionStr.equals("delete")){i = Jcwh.btn_delReaderActionPerformed(e, map);}else{i = Jcwh.btn_saveReaderActionPerformed(e,map,optionStr);}if (i == 1) {String showInfo = "";if(optionStr.equals("save")){showInfo = "读者添加成功!";}else if(optionStr.equals("update")){showInfo = "读者修改成功!";}else if(optionStr.equals("delete")){showInfo = "读者删除成功!";}JOptionPane.showMessageDialog(null, showInfo);// 清空全部文本框clearAllTextfield();}}});closeBtn.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {dispose(); // 释放当前窗体}});this.addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) { // 关闭当前窗口dispose(); // 释放当前窗体}});}private void ggFrame(String str) {setLayout(null);setTitle("添加读者信息");setSize(500, 230);lbreaderid.setBounds(50, 50, 50, 20);tf_readerid.setBounds(110, 50, 100, 20);lbreadername.setBounds(240, 50, 50, 20);tf_readername.setBounds(300, 50, 100, 20);lbreadertype.setBounds(50, 80, 50, 20);tf_readertype.setBounds(110, 80, 100, 20);tf_readertype.add("教师");tf_readertype.add("学生");tf_readertype.add("职工");lbsex.setBounds(240, 80, 50, 20);tf_sex.setBounds(300, 80, 100, 20);tf_sex.add("男");tf_sex.add("女");lbmax_num.setBounds(50, 110, 50, 20);tf_max_num.setBounds(110, 110, 100, 20);lbdays_num.setBounds(240, 110, 50, 20);tf_days_num.setBounds(300, 110, 100, 20);saveBtn.setBounds(150, 150, 80, 25);closeBtn.setBounds(280, 150, 80, 25);if(str.equals("save")){setTitle("添加读者");}else if(str.equals("update")){setTitle("修改读者");lbreaderid_c.setBounds(100, 10, 50, 20);tf_readerid_c.setBounds(160, 10, 100, 20);tf_readerid.setEditable(false);queryBtn.setBounds(280, 10, 80, 20);add(lbreaderid_c);add(tf_readerid_c);add(queryBtn);queryBtn.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {HashMap<String, Object> map = new HashMap<String, Object>();map.put("readerid", tf_readerid_c);Reader reader = (Reader)Jcwh.btn_queryReaderActionPerformed(e,map).get("reader");if(reader!=null){tf_readerid.setText(reader.getId());tf_readername.setText(reader.getReadername());tf_readertype.select(reader.getReadertype());tf_sex.select(reader.getSex());tf_days_num.setText(String.valueOf(reader.getDays_num()));tf_max_num.setText(String.valueOf(reader.getMax_num()));}}});saveBtn.setLabel("修改");//将按钮显示文字修改成“修改”}else if(str.equals("delete")){setTitle("删除图书");lbreaderid_c.setBounds(100, 10, 50, 20);tf_readerid_c.setBounds(160, 10, 100, 20);tf_readerid.setEditable(false);queryBtn.setBounds(280, 10, 80, 20);add(lbreaderid_c);add(tf_readerid_c);add(queryBtn);queryBtn.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {HashMap<String, Object> map = new HashMap<String, Object>();map.put("readerid", tf_readerid_c);Reader reader = (Reader)Jcwh.btn_queryReaderActionPerformed(e,map).get("reader");if(reader!=null){tf_readerid.setText(reader.getId());tf_readername.setText(reader.getReadername());tf_readertype.select(reader.getReadertype());tf_sex.select(reader.getSex());tf_days_num.setText(String.valueOf(reader.getDays_num()));tf_max_num.setText(String.valueOf(reader.getMax_num()));}}});saveBtn.setLabel("删除");//将按钮显示文字修改成“删除”}add(lbreaderid);add(lbreadername);add(lbreadertype);add(lbsex);add(lbmax_num);add(lbdays_num);add(tf_readerid);add(tf_readername);add(tf_max_num);add(tf_days_num);add(tf_readertype);add(tf_sex);add(saveBtn);add(closeBtn);setLocationRelativeTo(null);setVisible(true);}private void clearAllTextfield() {tf_readerid.setText("");tf_readername.setText("");tf_max_num.setText("");tf_days_num.setText("");}public static void main(String[] args) {ReaderManeger r = new ReaderManeger("update");}}5.借书public class Borrow extends Frame {private static final long serialVersionUID = -1036076990599464079L;String SepLine = "-------------------------------------------------";Label lbbookid = new Label("图书编号");Label lbreaderid = new Label("读者编号");TextField tf_bookid = new TextField();TextField tf_readerid = new TextField();Button queryBtn = new Button("查询");Label lbbookinfo = new Label(SepLine + "图书信息" + SepLine); Label lbbookname = new Label("图书名称:");Label tf_bookname = new Label("xx");Label lbauthor = new Label("作者:");Label tf_author = new Label("xx");Label lbpublisher = new Label("出版社:");Label tf_publisher = new Label("xx");Label lbpublish_time = new Label("出版时间:");Label tf_publish_time = new Label("xx");Label lbprice = new Label("定价:");Label tf_price = new Label("xx");Label lbstock = new Label("库存数量:");Label tf_stock = new Label("xx");Label lbreaderinfo = new Label(SepLine + "读者信息" + SepLine); Label lbreadername = new Label("读者姓名:");Label tf_readername = new Label("xx");Label lbreadertype = new Label("读者类型:");Label tf_readertype = new Label("xx");Label lbmax_num = new Label("最大可借数:");Label tf_max_num = new Label("xx");Label lbdays_num = new Label("最大可借天数:");Label tf_days_num = new Label("xx");Label lbborrowinfo = new Label(SepLine + "借阅信息" + SepLine); Label lbborrowednum = new Label("该读者已借图书数量:"); Label tf_borrowednum = new Label("xx");Label lbif_borrow = new Label("该读者是否可借所选图书:"); Label tf_if_borrow = new Label("xx");Label lbborrow_date = new Label("借阅日期:");Label tf_borrow_date = new Label("xx");Button borrowBtn = new Button("借出");Button closeBtn = new Button("关闭");public Borrow() {setLayout(null);setTitle("借阅图书");setSize(500, 420);this.setForeground(Color.BLACK); // 设置前景色为黑色lbbookid.setBounds(30, 40, 50, 25); // 图书编号tf_bookid.setBounds(90, 40, 90, 20);lbreaderid.setBounds(200, 40, 50, 25); // 读者编号tf_readerid.setBounds(260, 40, 90, 20);queryBtn.setBounds(370, 40, 80, 25); // 查询按钮lbbookinfo.setBounds(30, 70, 440, 25); // 图书信息提示条lbbookname.setBounds(30, 100, 60, 25); // 图书名称tf_bookname.setBounds(90, 100, 200, 25);lbauthor.setBounds(310, 100, 60, 25); // 作者tf_author.setBounds(370, 100, 90, 25);lbpublisher.setBounds(30, 125, 60, 25); // 出版社tf_publisher.setBounds(90, 125, 200, 25);lbpublish_time.setBounds(310, 125, 60, 25); // 出版时间tf_publish_time.setBounds(370, 125, 90, 25);lbprice.setBounds(30, 150, 60, 25); // 定价tf_price.setBounds(90, 150, 200, 25);lbstock.setBounds(310, 150, 60, 25); // 库存数量tf_stock.setBounds(370, 150, 90, 25);lbreaderinfo.setBounds(30, 180, 440, 25); // 读者信息提示条lbreadername.setBounds(30, 205, 60, 25); // 读者姓名tf_readername.setBounds(90, 205, 90, 25);lbreadertype.setBounds(310, 205, 60, 25); // 读者类型tf_readertype.setBounds(370, 205, 90, 25);lbmax_num.setBounds(30, 230, 75, 25); // 最大可借数tf_max_num.setBounds(105, 230, 90, 25);lbdays_num.setBounds(310, 230, 85, 25); // 最大可借天数tf_days_num.setBounds(395, 230, 70, 25);lbborrowinfo.setBounds(30, 260, 440, 25); // 借阅信息提示条lbborrowednum.setBounds(30, 285, 120, 25);// 已借图书数量tf_borrowednum.setBounds(150, 285, 50, 25);lbif_borrow.setBounds(30, 310, 145, 25); // 是否可借tf_if_borrow.setBounds(175, 310, 50, 25);lbborrow_date.setBounds(30, 335, 60, 25);// 借书日期tf_borrow_date.setBounds(90, 335, 100, 25);borrowBtn.setBounds(160, 365, 80, 25);// 借出按钮borrowBtn.setEnabled(false); // 开始时禁用借出按钮closeBtn.setBounds(260, 365, 80, 25);// 关闭按钮queryBtn.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) { btn_querywActionPerformed(e); } }); borrowBtn.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) { btn_borrowActionPerformed(e); } });closeBtn.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) { setForeground(Color.BLACK); dispose(); } }); this.addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) {setForeground(Color.BLACK); // 设置前景色为黑色dispose(); // 关闭窗体}});add(lbbookid);add(lbreaderid);add(queryBtn);add(lbbookinfo);add(lbbookname);add(lbauthor);add(lbpublisher);add(lbpublish_time);add(lbprice);add(lbstock);add(lbreaderinfo);add(lbreadername);add(lbreadertype);add(lbmax_num);add(lbdays_num);add(lbborrowinfo);add(lbborrowednum);add(lbif_borrow);add(lbborrow_date);add(borrowBtn);add(closeBtn);setLocationRelativeTo(null); // 使窗体在屏幕上居中放置setVisible(true); // 使窗体可见setForeground(Color.RED); // 设置前景色为红色add(tf_bookid);add(tf_readerid);add(tf_bookname);add(tf_author);add(tf_publisher);add(tf_publish_time);add(tf_price);add(tf_stock);add(tf_readername);add(tf_readertype);add(tf_max_num);add(tf_days_num);add(tf_borrowednum);add(tf_if_borrow);add(tf_borrow_date);}// 图书和读者查询private void btn_querywActionPerformed(ActionEvent e) {String bookid = tf_bookid.getText();String readerid = tf_readerid.getText();// 如果图书编号或读者编号两者均为空,或者有一个为空,则返回if (bookid.equals("") || readerid.equals("")) {JOptionPane.showMessageDialog(null, "图书编号和读者编号均不能为空!");init(); // 重新初始化各参数并禁止借出按钮return;}// 按编号查询图书,结果存入book对象中Book book = BookSelect.SelectBookById(bookid);if (book != null) { // 如果查询到结果,将其显示在各文本框中tf_bookname.setText(book.getBookname());tf_author.setText(book.getAuthor());tf_publisher.setText(book.getPublisher());tf_publish_time.setText(book.getPublish_time().toString());tf_price.setText(String.valueOf((book.getPrice())));tf_stock.setText(String.valueOf(book.getStock()));} else {JOptionPane.showMessageDialog(null, "图书编号有误,查无此书!");init(); // 重新初始化各参数并禁止借出按钮return;}if (book.getStock() == 0) {JOptionPane.showMessageDialog(null, "图书已无库存,无法借阅!");init(); // 重新初始化各参数并禁止借出按钮return;}// 按编号查询读者,结果存入reader对象中Reader reader = ReaderSelect.selectReaderById(readerid);// 如果查询到结果,将其显示在各文本框中if (reader != null) {tf_readername.setText(reader.getReadername());tf_readertype.setText(reader.getReadertype());tf_max_num.setText(String.valueOf(reader.getMax_num()));tf_days_num.setText(String.valueOf(reader.getDays_num()));} else {JOptionPane.showMessageDialog(null, "读者编号有误,查无此人!");init(); // 重新初始化各参数并禁止借出按钮return;}// 查询指定读者是否已借过指定图书且未归还if (IfBorrowBack.findbook(bookid, readerid)) {JOptionPane.showMessageDialog(null, "该读者已借阅所选图书,且未归还!");init(); // 重新初始化各参数并禁止借出按钮return;}// 统计读者所借图书数量int borrowednum = statborrowednum(readerid);tf_borrowednum.setText(String.valueOf(borrowednum));// 如果读者已借图书尚未超出其允许最大借书量,则允许其继续借阅所选图书if (borrowednum < reader.getMax_num()) {tf_if_borrow.setText("是");// 创建一个简单日期格式对象,注意:MM一定要用大写SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");// 创建日期变量,其内容为当前日期Date currentdate = new Date();// 将日期按指定格式输出String borrowdate = sdf.format(currentdate);tf_borrow_date.setText(borrowdate);borrowBtn.setEnabled(true); // 使借出按钮有效} else {JOptionPane.showMessageDialog(null, "该读者借书过多,无法继续借阅!");init(); // 重新初始化各参数并禁止借出按钮return;}}// 填写借出图书记录private void btn_borrowActionPerformed(ActionEvent e) {String sql;String bookid = tf_bookid.getText();String readerid = tf_readerid.getText();String borrowdate = tf_borrow_date.getText();// 为borrow表增加借书记录sql = "insert into borrow (book_id,reader_id,"+ "borrow_date,if_back) values('" + bookid + "','" + readerid + "','" + borrowdate + "','否')";。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

import .*;import .*;import .*;import .*;//---------------------------------------------------------------------------------------------------------class Tsgl {public static void main(String args[]) {dbframe db = new dbframe("图书管理程序");}}// 图书管理系统主界面class dbframe extends Frame implements ActionListener {MenuBar daohang = new MenuBar(); // 建立菜单栏Menu mfile = new Menu("功能"); // 建立“功能”菜单组Menu mhelp = new Menu("帮助"); // 建立“帮助”菜单组MenuItem mdenglu = new MenuItem("登陆");MenuItem mchaxun = new MenuItem("查询");MenuItem mtianjia = new MenuItem("添加");MenuItem mshanchu = new MenuItem("删除");MenuItem mexit = new MenuItem("退出");MenuItem mhelpp = new MenuItem("关于");Denglu pdenglu=new Denglu();Ptianjia ptianjia = new Ptianjia();Pmain pmain = new Pmain();Pchaxun pchaxun = new Pchaxun();Pshanchu pshanchu = new Pshanchu();dbframe(String s) { // 在窗口上添加菜单选项setTitle(s);(mdenglu);(mtianjia);(mchaxun);(mshanchu);(mexit);(mhelpp);(mfile);(mhelp);setMenuBar(daohang);add(pmain);addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) {(0);}});setBounds(200, 200, 340, 250);setResizable(false);setVisible(true);(this);(this);(this);(this);(this);(this);validate();} // 窗口事件监听public void actionPerformed(ActionEvent e) { if () == mexit)(0);if()==mdenglu){removeAll();add(pdenglu);validate();}if () == mtianjia) {removeAll();add(ptianjia);validate();} // 图书添加功能if () == mchaxun) {removeAll();add(pchaxun);validate();} // 图书查询功能if () == mshanchu) {removeAll();add(pshanchu);validate();} // 图书删除功能if () == mhelpp) {(this, "欢迎使用图书管理系统", "关于本系统",;}} // 各功能菜单事件监听}//class Ptianjia extends Panel implements ActionListener { TextField tname, tauthor, tpublish, tdate, tcomment;Label lname, lauthor, lpublish, ldate, lcomment;Button btn;Ptianjia() {setLayout(null);btn = new Button("添加"); // 创建“添加”按钮tname = new TextField();tauthor = new TextField();tpublish = new TextField();tdate = new TextField();tcomment = new TextField(); // 创建5个文本框lname = new Label("书名");lauthor = new Label("作者");lpublish = new Label("出版社");ldate = new Label("出版日期");lcomment = new Label("评论");add(lname);add(tname);add(lauthor);add(tauthor);add(lpublish);add(tpublish);add(ldate);add(tdate);add(lcomment);add(tcomment);add(btn); // 添加“按钮”到窗口面板上(10, 10, 70, 25);(90, 10, 220, 25);(10, 40, 70, 25);(90, 40, 220, 25);(10, 70, 70, 25);(90, 70, 220, 25);(10, 100, 70, 25);(90, 100, 220, 25);(10, 130, 70, 25);(90, 130, 220, 25);(130, 160, 70, 25); // 设置按钮位置(this); // 设置按钮监听setSize(340, 250); // 设置窗口大小setBackground; // 设置窗口背景颜色setVisible(true);validate();}public void actionPerformed(ActionEvent e) {String sname = ();String sauthor = ();String spublish = ();String sdate = ();String scomment = ();String insertstr = "insert into book values" + "(" + "'" + sname + "'"+ "," + "'" + sauthor + "'" + "," + "'" + spublish + "'" + ","+ "'" + sdate + "'" + "," + "'" + scomment + "'" + ")"; // SQL 语句Connection con;Statement sta;ResultSet rs;try {(""); // 加载JDBC驱动} catch (ClassNotFoundException ee) {"" + ee);}try {con = ("jdbc:oracle:thin:@localhost:1521:orcl", "sa", "orcl"); // 连接数据库sta = ();(insertstr); // 执行SQL语句(); // 关闭数据库("");("");("");("");(""); // 重新初始化文本框内容(this, "添加成功", "图书管理系统",;} catch (SQLException eee) {"" + eee);("");("");("");("");("");(this, "添加失败", "图书管理系统",;}}}class Pmain extends Panel { // 窗口面板布局Label l1 = new Label("图书管理系统", ;Label l2 = new Label("计算机学院", ;Label l3 = new Label("", ;Label l4 = new Label("作者:JHL", ;Pmain() {setLayout(null);setBackground;add(l1);add(l2);add(l3);add(l4);(10, 60, 320, 40);(240, 120, 80, 22);(240, 142, 80, 22);(240, 164, 80, 22);setSize(340, 250);setVisible(true);validate();}}class Pchaxun extends Panel implements ActionListener {// 图书查询Choice cchaxun;TextField tchaxun;Button btnchaxun;TextArea tachaxun;Pchaxun() {setLayout(null);cchaxun = new Choice(); // 创建下拉菜单("书名");("作者");("出版社");tchaxun = new TextField();btnchaxun = new Button("查询"); // 创建按钮tachaxun = new TextArea(); // 创建多行文本框add(cchaxun);add(tchaxun);add(btnchaxun);add(tachaxun);("");(10, 10, 65, 20);(85, 10, 180, 20);(275, 10, 40, 20);(10, 40, 305, 145);(0); // 下拉菜单的初始选项setSize(340, 250); // 设置窗口大小setBackground;setVisible(true);(this);validate();}public void actionPerformed(ActionEvent e) {int i = ();String s = ();if (""))(this, "查询内容不能为空", "查询系统",;else {Connection con;Statement sql;ResultSet rs;try {(""); // 加载JDBC驱动} catch (ClassNotFoundException ee) {"" + ee);}try {con = ("jdbc:oracle:thin:@localhost:1521:orcl", "sa", "orcl");// 连接数据库sql = ();if (i == 0) // 根据下拉菜单的选项执行不同的SQL语句rs = ("select * from book where bookName ="+ "'" + s + "'");else if (i == 1)rs = ("select * from book where author ="+ "'" + s + "'");elsers = ("select * from book where publisher ="+ "'" + s + "'");("");String panduan = "false";while ()) {panduan = "true";("书名:" + (1) + "\n");("作者:" + (2) + "\n");("出版社:" + (3) + "\n");("出版日期:" + (4) + "\n");("评论:" + (5) + "\n");} // 显示查询到的图书信息rs = ("select count(*) from book"); // 统计所有图书数while ()) {("图书馆暂有" + (1) + "本图书");} // 显示所有图书数量信息(); // 关闭数据库if ("false"))(this, "没有该记录", "查询系统",;} catch (SQLException eee) {}}}}class Pshanchu extends Panel implements ActionListener { // 删除功能模块Choice cshanchu;TextField tshanchu;Button btnshanchu;Label l1 = new Label("", ;Label l2 = new Label("计算机学院", ;Label l3 = new Label("", ;Label l4 = new Label("作者:ZCS", ;Pshanchu() {setLayout(null);cshanchu = new Choice(); // 创建下拉菜单("书名");tshanchu = new TextField();btnshanchu = new Button("删除"); // 创建按钮add(cshanchu);add(tshanchu);add(btnshanchu);add(l1);add(l2);add(l3);add(l4); // 添加标签、按钮等到窗口面板("");(10, 10, 65, 20);(85, 10, 180, 20);(275, 10, 40, 20);(10, 40, 300, 40);(240, 130, 80, 22);(240, 152, 80, 22);(240, 174, 80, 22);(0);setSize(340, 250); // 设置窗口大小setBackground;setVisible(true);(this);validate();}public void actionPerformed(ActionEvent e) {String s = ();if (""))(this, "请输入要删除的图书", "删除功能",;else {Connection con;Statement sql;ResultSet rs;try {("");} catch (ClassNotFoundException ee) {"" + ee);}try {con = ("jdbc:oracle:thin:@localhost:1521:orcl", "sa", "orcl");sql = ();rs = ("select * from book where bookName ="+ "'" + s + "'");if (!())(this, "没有该图书", "删除功能",;else {int n = (this, "确认删除吗","删除功能", ;if (n == {("delete from book where bookName ="+ "'" + s + "'");(this, "删除成功", "删除功能",;("");} else("");();}} catch (SQLException eee) {}}}}class Denglu extends Panel implements ActionListener {Label lzhanghao;TextField tzhanghao;Label lmima;TextField tmima;Button bdenglu;Denglu(){setLayout(null);lzhanghao=new Label("账号");tzhanghao=new TextField();lmima=new Label("密码");tmima=new TextField();bdenglu=new Button("登陆");add(lzhanghao);add(tzhanghao);add(lmima);add(tmima);add(bdenglu);("");("");(50, 25, 50, 30);(100, 30, 200, 20);(50, 80, 50, 30);(100, 80, 200, 20);(140, 130, 50, 30);setBackground;setVisible(true);(this);validate();}public void actionPerformed(ActionEvent e) { String x=();String y=();if("weifang")&&("123") ){(this, "登陆成功", "提示",;}else{(this, "账号或者密码错误","提示",;}}}。

相关文档
最新文档