数据结构课程设计-单链表实现图书管理系统

界面
数据结构课设本来是用c来做的,但实在是对c不太熟悉,就用java做了一个(前端代码用netBeans拖拽形成的)

问题描述

设计一个系统,对图书信息进行管理,信息描述:
有关该系统基本信息的描述,如:图书名称、图书编号、单价、作者、存在状态、借书人姓名、性别、学号等。

设计思路

首先这个系统有三个类,Book.BorrProce.Person三个类,也就是说要有三个链表来存储这些数据,java中有继承的特性,所以便想抽象出一个类来,这时候Things类就出来了,Things是上面三个类的父类. Node类,类中有数据域和指针域,数据域是Things类型,指针域是Node类型.
SingleLinkList类,链表都是由一个一个的节点构成的,但是链表的头结点只有指针域没有数据域(数据域为空).这个类里面都是定义对链表的操作(增删改查).增删节点他们三个类是可以共同使用一个方法的,但涉及到具体数据的话就需要强制类型转换了.然后就使用SingleLinkList类中的方法来实现对数据的操作.

需求分析

要求
  • 1、新进图书基本信息的输入,图书基本信息保存在数据文件中。
  • 2、图书基本信息的查询。
  • 3、对撤消图书信息的删除。
  • 4、为借书人办理注册。
  • 5、办理借书手续(非注册会员不能借书)。
  • 6、办理还书手续。
  • 7、统计图书库存、已借出图书数量。
详细功能
  • A.添加图书:系统提示用户添加书籍,添加的具体内容是书名,ID,价格,作者,总添加量(默认为10),借出量(默认为0)。
  • B.查询图书:系统设置了模糊查询的方法,通过关键字既可以查到相应的书籍。
  • C.删除图书:用户通过输入书的名称来删除某一种书。
  • D.借阅图书:用户首先需要登录,否则不可以借阅,通过输入书的名字,来实现借阅图书,借阅成功书的总数会减1,书的借出量会加1。
  • E.归还图书:用户首先需要登录,否则不可以还书,通过输入借书人的名字,来实现归还图书,归还成功后书的总数会加1,书的借出量会减1。
  • F.查询所有图书:系统设置查询所有图书的功能.
  • G.通过用户名和账号登录图书管理系统,如果没有账号,可以注册.

概要设计

如图所示:
界面1

程序源代码

下面的代码结合起来放到一个java文件中是可以运行的,整个项目的代码会在最后打包.
代码
可以看到图片上有两个包improve是后台代码包,view是前端代码包 下面是两个包中类的介绍
代码
代码
每个类下面都有隐藏的源代码点击▼查看
引入的包

1
2
3
4
5
6
7
8
import javax.swing.*;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.*;
import java.io.*;
import javax.annotation.processing.Filer;
import java.text.SimpleDateFormat;
import java.util.Date;

Book类

点击显/隐内容
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class Book extends Things{
String name;
int id ;
String price;
String author;
int sum;
int rentCount;
Book()
{

}
Book(String name,int id,String price,String author,int sum,int rentCount)
{
this.name=name;
this.id=id;
this.price=price;
this.author=author;
this.sum=sum;
this.rentCount=rentCount;
}
@Override
public String toString() {
return "name=" + name + ", id=" + id + ", price=" + price + ", author=" + author + ", sum=" + sum
+ ", rentCount=" + rentCount;
}
}

Person类
点击显/隐内容
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Person extends Things{

Person()
{}
Person(String name,String id)
{
this.name=name;
this.id=id;
}
@Override
public String toString() {
return "name=" + name + ", id=" + id ;
}
}

BorrProce类
点击显/隐内容
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class BorrProce extends Things {
String userName;
String bookName;
int bookNum;
String date;
BorrProce()
{}
BorrProce(String userName,String bookName,int bookNum,String date)
{
this.userName=userName;
this.bookName=bookName;
this.bookNum=bookNum;
this.date=date;
}
@Override
public String toString() {
return "userName=" + userName + ", bookName=" + bookName + ", bookNum=" + bookNum + ", date=" + date;
}

}

Things类
点击显/隐内容
1
2
3
4
5
6
7
8
9
class Things {
String name;
String id;
@Override
public String toString() {
// TODO Auto-generated method stub
return super.toString();
}
}

Node类
点击显/隐内容
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Node {
Things data;
Node next;
Node()
{}
Node(Things data)
{
this.data=data;
}
Node(Person data)
{
this.data=data;
}
Node(Book data)
{
this.data=data;
}
Node(BorrProce data)
{
this.data=data;
}
}

SingleLinkList类
点击显/隐内容
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
class SingleLinkList {
// 建立头结点
Node header=new Node();
/*
* 插入节点的方法
* */
public void insertNode(Node InsNode)
{
// 搞一个临时变量,把头节点赋值给他
Node temp =header;
// 当没有到文件末尾就一直循环 temp.next是判断下一个还有没有节点,当循环退出就说明到了节点的末尾
while(temp.next!=null)
{
temp=temp.next;
}
// 现在将添加的节点放到节点的最后
temp.next=InsNode;
}
// 插入到任意节点
public void InsAnyNode(int i,Node node)
{
// 搞一个临时变量,把头节点赋值给他
if(i<0||i>size())
{
System.out.println("您输入的节点位置不对");
}else {
int count=0;
Node temp =header;
while(temp.next!=null)
{
count++;
if(i==count)
{
// 增加了个临时变量来保存数据
Node tempChange=new Node();
tempChange=temp.next;
temp.next=node;
node.next=tempChange;
break;
}else {
temp=temp.next;
}

}
}
}
/*
* 删除节点的方法
* */
public void deleteNode(String name)
{
// 搞一个临时变量,把头节点赋值给他
Node temp =header;
// 当没有到文件末尾就一直循环 temp.next是判断下一个还有没有节点,当循环退出就说明到了节点的末尾
while(temp.next!=null)
{
// 下面是判断当前temp的下一个元素是否和我们要删除的节点一致 这里考虑为什么要比较temp的下一个节点
// 而不比较它本身
// if((temp.next.data).name.equals(name))
Book book=((Book)temp.next.data);
if(book.name.equals(name))
{
int n = JOptionPane.showConfirmDialog(null, "确认删除"+" '"+book.name+" '"+"这本书吗?", "确认删除",JOptionPane.YES_NO_OPTION);
if(n==JOptionPane.YES_OPTION)
{
// 如果一致的话将当前节点下一个节点改为temp.next.next;
temp.next=temp.next.next;
System.out.println("删除结束");
// 跳出循环体,没有必要再往下面进行了,已经找到了
JOptionPane.showMessageDialog(null, "删除成功");
return;
} else
{
return;
}
}else
{
// 对temp重新赋值 进行下一轮的循环
temp=temp.next;
}
}
JOptionPane.showMessageDialog(null, "没有找到相关书籍");
}
/*
* 删除节点的方法
* */
public void deleteNodeBorr(String name)
{
// 搞一个临时变量,把头节点赋值给他
Node temp =header;
// 当没有到文件末尾就一直循环 temp.next是判断下一个还有没有节点,当循环退出就说明到了节点的末尾
while(temp.next!=null)
{
// 下面是判断当前temp的下一个元素是否和我们要删除的节点一致 这里考虑为什么要比较temp的下一个节点
// 而不比较它本身
// if((temp.next.data).name.equals(name))
if(((BorrProce)temp.next.data).userName.equals(name))
{
// 如果一致的话将当前节点下一个节点改为temp.next.next;
temp.next=temp.next.next;
System.out.println("删除结束");
// 跳出循环体,没有必要再往下面进行了,已经找到了
JOptionPane.showMessageDialog(null, "还书成功");

return;
}else
{
// 对temp重新赋值 进行下一轮的循环
temp=temp.next;
}
}
JOptionPane.showMessageDialog(null, "没有找到相关书籍");
}
/*
* 下面是查找某个节点的方法
* */

public Node getNode(int i)
{
Node reNode=new Node();
// 搞一个临时变量,把头节点赋值给他
if(i<0||i>size())
{
System.out.println("您输入的节点位置不对");
}else {
int count=0;
Node temp =header;
while(temp.next!=null)
{
count++;
if(i==count)
{
reNode.data=temp.next.data;
break;
}else {
temp=temp.next;
}

}
}
return reNode;
}

/*
* 下面这个方法是修改链表中的数据
* */
public void updateNode(String oldName,String newName)
{
// 搞一个临时变量,把头节点赋值给他
Node temp =header;
// 当没有到文件末尾就一直循环 temp.next是判断下一个还有没有节点,当循环退出就说明到了节点的末尾
while(temp.next!=null)
{
// 下面是判断当前temp的下一个元素是否和我们要更新的节点一致
if(temp.next.data.equals(oldName))
{
// 如果一致的话,更新数据
temp.next.data.name=newName;
System.out.println("更新结束");
// 跳出循环体,没有必要再往下面进行了,已经更新好了
return;
}else
{
// 对temp重新赋值 进行下一轮的循环
temp=temp.next;
}
}
System.out.println("此链表中没有你要的节点");
}
/*
* size方法是统计这个链表有多少个节点
* */
public int size()
{
Node temp = header;
int size=0;
while(temp.next!=null)
{
size++;
temp=temp.next;
}
return size;
}

// 返回列表中的所有节点
public Node[] reNode(SingleLinkList list)
{
Node[] reNode=new Node[list.size()];
Node temp =header;
int i=0;
while(temp.next!=null)
{
temp=temp.next;
reNode[i]=temp;
i++;
}
return reNode;
}
public StringBuffer printList()
{
System.out.println("打印链表:");
Node temp =header;
StringBuffer strb=new StringBuffer();
while(temp.next!=null)
{
temp=temp.next;
strb.append(temp.data.toString()+"\r\n");
}
return strb;
}
}

UtilClass类
点击显/隐内容
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
class UtilClass {
public static String strName;
// 从文件中读写出用户数据并写入链表中
public static SingleLinkList readUtilP(String path)
{
SingleLinkList list=new SingleLinkList();
try {
FileReader fr=new FileReader(path);
BufferedReader buf=new BufferedReader(fr);
String str=null;
while((str=buf.readLine())!=null)
{
String [] arr = str.split("\\s+");
Person p=new Person(arr[0],arr[1]);
Node n1=new Node(p);
list.insertNode(n1);

}
buf.close();
fr.close();
}catch (Exception e) {
e.printStackTrace();
}
return list;
}
// 从文件中读写出书的数据并写入链表中
public static SingleLinkList readUtilB(String path)
{
SingleLinkList list=new SingleLinkList();
try {
FileReader fr=new FileReader(path);
BufferedReader buf=new BufferedReader(fr);
String str=null;
int i = 0;
while((str=buf.readLine())!=null)
{
String [] arr = str.split(",");
// if(i == 0) {
// arr[0] = arr[0].substring(1);
// }
Book b=new Book(arr[0],Integer.parseInt(arr[1]),arr[2],arr[3],Integer.parseInt(arr[4]),Integer.parseInt(arr[5]));
Node n1=new Node(b);
list.insertNode(n1);
i++;
}
buf.close();
fr.close();
}catch (Exception e) {
e.printStackTrace();
}
return list;
}
// 从文件中读写出书的数据并写入链表中
public static SingleLinkList readUtilBorrP(String path)
{
SingleLinkList list=new SingleLinkList();
try {
FileReader fr=new FileReader(path);
BufferedReader buf=new BufferedReader(fr);
String str=null;
int i = 0;
while((str=buf.readLine())!=null)
{
String [] arr = str.split(",");
// if(i == 0) {
// arr[0] = arr[0].substring(1);
// }
BorrProce borr=new BorrProce(arr[0],arr[1],Integer.parseInt(arr[2]),arr[3]);
Node n1=new Node(borr);
list.insertNode(n1);
i++;
}
buf.close();
fr.close();
}catch (Exception e) {
e.printStackTrace();
}
return list;
}
// 从链表中读数据并写入磁盘
public static void writeUtilP(String path,SingleLinkList list)
{
try {
FileWriter file=new FileWriter(path);
BufferedWriter bufw=new BufferedWriter(file);
Node[] node=list.reNode(list);
String str=null;
for(int i=0;i<node.length;i++)
{
str=node[i].data.name+"\t"+node[i].data.id;
bufw.write(str);
bufw.newLine();
}
bufw.close();
file.close();
} catch (IOException e) {
e.printStackTrace();
}

}
// 从链表中读数据并写入磁盘
public static void writeUtilB(String path,SingleLinkList list)
{
try {
FileWriter file=new FileWriter(path);
BufferedWriter bufw=new BufferedWriter(file);
Node[] node=list.reNode(list);
String str=null;
for(int i=0;i<node.length;i++)
{
Things t=node[i].data;
Book book=(Book)t;
str=book.name+","+book.id+","+book.price+","+book.author+","+book.sum+","+book.rentCount;
bufw.write(str);
bufw.newLine();
}
bufw.close();
file.close();
} catch (IOException e) {
e.printStackTrace();
}
// try {
// FileWriter file=new FileWriter(path);
// BufferedWriter bufw=new BufferedWriter(file);
// StringBuffer strb=list.printList();
// String str=new String(strb);
// bufw.write(str);
// bufw.close();
// file.close();
// } catch (IOException e) {
// e.printStackTrace();
// }
//
}
// 从链表中读数据并写入磁盘
public static void writeUtilBorrP(String path,SingleLinkList list)
{
try {
FileWriter file=new FileWriter(path);
BufferedWriter bufw=new BufferedWriter(file);
Node[] node=list.reNode(list);
String str=null;
for(int i=0;i<node.length;i++)
{
Things t=node[i].data;
BorrProce borr=(BorrProce)t;
str=borr.userName+","+borr.bookName+","+borr.bookNum+","+borr.date;
bufw.write(str);
bufw.newLine();
}
bufw.close();
file.close();
} catch (IOException e) {
e.printStackTrace();
}

}
// 实现输入姓名看身份的功能
public static String VerfyName(String name,SingleLinkList list)
{
String id="查无此人";
for(int i=0;i<list.size();i++)
{
Node[] arr=list.reNode(list);
if(name.equals(arr[i].data.name))
{
id=arr[i].data.id;
}
}
return id;
}
// 实现模糊查询图书
public static StringBuffer fuzzyQ(String fuzzyName,SingleLinkList list)
{
boolean flag=true;
StringBuffer strb=new StringBuffer();
for(int i=0;i<list.size();i++)
{
Node[] arr=list.reNode(list);
// if(((Book)arr[i].data).name.contains(fuzzyName))
if(((Book)arr[i].data).name.contains(fuzzyName))
{
strb.append(arr[i].data.toString()+"\r\n");
System.out.println(arr[i].data.toString());

flag=false;
}else if(i==list.size()-1&&flag==true)
{
JOptionPane.showMessageDialog(null, "未找到相关书籍");
}
}
return strb;
}
// 实现精确查询图书
public static StringBuffer pinPiontQ(String pinPiontName,SingleLinkList list)
{
boolean flag=true;
StringBuffer strb=new StringBuffer();
for(int i=0;i<list.size();i++)
{
Node[] arr=list.reNode(list);
// if(((Book)arr[i].data).name.contains(fuzzyName))
if(((Book)arr[i].data).name.equals(pinPiontName))
{
strb.append(arr[i].data.toString()+"\r\n");
System.out.println(arr[i].data.toString());
flag=false;

}else if(i==list.size()-1&&flag==true)
{
JOptionPane.showMessageDialog(null, "未找到相关书籍");
strb.append("-1");
}
}
return strb;
}
// 实现查询借阅手续(还书)
public static StringBuffer borrProQ(String userName,SingleLinkList list,SingleLinkList book,String bookPath,String borrProPath)
{
boolean flag=true;
StringBuffer strb=new StringBuffer();
for(int i=0;i<list.size();i++)
{
Node[] arr=list.reNode(list);

// if(((Book)arr[i].data).name.contains(fuzzyName))
BorrProce b=(BorrProce)arr[i].data;
if(b.userName.equals(userName))
{
strb.append(arr[i].data.toString()+"\r\n");
System.out.println(arr[i].data.toString());
flag=false;
int n = JOptionPane.showConfirmDialog(null, "确认还"+" '"+b.bookName+" '"+"这本书吗?", "确认还书",JOptionPane.YES_NO_OPTION);
if(n==JOptionPane.YES_OPTION)
{
for(int j=0;j<book.size();j++)
{
Node[] arrB=book.reNode(book);
BorrProce borr =((BorrProce)arr[i].data);
Book bo=((Book)arrB[j].data);
if(borr.bookName.equals(bo.name))
{
((Book)arrB[j].data).sum++;
((Book)arrB[j].data).rentCount--;
UtilClass.writeUtilB(bookPath, book);
}
}

list.deleteNodeBorr(userName);
UtilClass.writeUtilBorrP(borrProPath, list);
}
}else if(i==list.size()-1&&flag==true)
{
JOptionPane.showMessageDialog(null, "您目前没有借阅书籍");
}
}
return strb;
}
// 实现用户注册
public static void register(String userName,String passWord,String path,SingleLinkList list)
{
for(int i=0;i<list.size();i++)
{
Node[] arr=list.reNode(list);
if(((Person)arr[i].data).name.equals(userName))
{
JOptionPane.showMessageDialog(null, "用户已注册");
return;
}
}
list.insertNode(new Node(new Person(userName,passWord)));
UtilClass.writeUtilP(path,list);
JOptionPane.showMessageDialog(null, "注册成功");
}
// 添加书籍
public static void addBook(String name,int id,String price,String author,int sum,int rentCount,String path,SingleLinkList list)
{
list.insertNode(new Node(new Book(name,id,price,author,sum,rentCount)));
UtilClass.writeUtilB(path,list);
JOptionPane.showMessageDialog(null, "添加成功");
}
// 删除图书
public static void deleteBook(String name,String path,SingleLinkList list)
{
list.deleteNode(name);
UtilClass.writeUtilB(path,list);

}
// 借书
public static void rentBook(String bookName,SingleLinkList list,String BorrPath,String bookPath,SingleLinkList BorrPL)
{
StringBuffer strb=UtilClass.pinPiontQ(bookName, list);
String str =new String(strb);
if(str.equals("-1"))
{
return ;
}
int n = JOptionPane.showConfirmDialog(null, "已找到"+str, "确认借阅",JOptionPane.YES_NO_OPTION);
// JOptionPane.showMessageDialog(null, "已找到"+((Book)arr[i].data).name);
if(n==JOptionPane.YES_OPTION)
{
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格
BorrPL.insertNode((new Node(new BorrProce(MainFrame.jTextField10.getText(), MainFrame.jTextField7.getText(), 1, df.format(new Date())))));
UtilClass.sRN(list, bookName);
UtilClass.writeUtilB(bookPath, list);
UtilClass.writeUtilBorrP(BorrPath, BorrPL);
JOptionPane.showMessageDialog(null, "借阅成功");
}
}
// 借书时的sum-1,rentCount+1
public static void sRN(SingleLinkList list,String bookName)
{
for(int i=0;i<list.size();i++)
{
Node[] arr=list.reNode(list);
// if(((Book)arr[i].data).name.contains(fuzzyName))
Book book=(Book)arr[i].data;
if(book.name.equals(bookName))
{
book.sum--;
book.rentCount++;

}
}
}
// 统计库存
public static String staInven(SingleLinkList list)
{
// 库存是多少
int sum=0;
// 一共有多少种书
int kind=list.size();

for(int i=0;i<list.size();i++)
{
Node[] arr=list.reNode(list);
Book book=(Book)arr[i].data;
sum+=book.sum;
}
return "书共有"+kind+"种"+"总库存是"+sum+"";
}
// 统计借出量
public static String staRent(SingleLinkList list)
{
// 借出量是多少
int sum=0;


for(int i=0;i<list.size();i++)
{
Node[] arr=list.reNode(list);
Book book=(Book)arr[i].data;
sum+=book.rentCount;
}
return "书的借出量为"+sum;
}
// 实现用户登录
public static void login(String userName,String passWord,SingleLinkList list)
{
String strName=userName;
String realPwd=UtilClass.VerfyName(userName, list);
if(realPwd.equals(passWord))
{
System.out.println("登录成功");
JOptionPane.showMessageDialog(null, "登录成功");
strName=userName;
MainFrame.jTextField10.setText(userName);
}else if(realPwd.equals("查无此人"))
{
System.out.println("此用户还没注册,赶紧去注册吧");
JOptionPane.showMessageDialog(null, "此用户还没注册,赶紧去注册吧");

}
else
{
System.out.println("密码好像错了那");
JOptionPane.showMessageDialog(null, "密码好像错了那");
}
}

}

NewJFrame类
点击显/隐内容
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
class NewJFrame extends javax.swing.JFrame {
// 把数据从文件中读到单链表中去
String path="./a.txt";
SingleLinkList list=UtilClass.readUtilP(path);
/**
* Creates new form NewJFrame
*/
public NewJFrame() {
initComponents();
}

/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {

jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("登录注册");
setResizable(false);

jLabel1.setText("用户名");

jLabel2.setText("密 码");

jTextField2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField2ActionPerformed(evt);
}
});

jButton1.setText("注册");
jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton1MouseClicked(evt);
}
});

jButton2.setText("登录");
jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton2MouseClicked(evt);
}
});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(162, 162, 162))
.addGroup(layout.createSequentialGroup()
.addGap(78, 78, 78)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(128, Short.MAX_VALUE))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(80, 80, 80)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(259, Short.MAX_VALUE)))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(61, 61, 61)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(78, 78, 78)
.addComponent(jButton1)
.addContainerGap(83, Short.MAX_VALUE))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(195, Short.MAX_VALUE)
.addComponent(jButton2)
.addGap(82, 82, 82)))
);

pack();
}// </editor-fold>//GEN-END:initComponents

private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField2ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jTextField2ActionPerformed

private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton2MouseClicked
// TODO add your handling code here:
UtilClass.login(jTextField2.getText(),jTextField1.getText(), list);
this.setVisible(false);
}//GEN-LAST:event_jButton2MouseClicked

private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
// TODO add your handling code here:
UtilClass.register(jTextField2.getText(),jTextField1.getText(),path,list);
}//GEN-LAST:event_jButton1MouseClicked
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
// End of variables declaration//GEN-END:variables

}

JTextFieldHintListener类
点击显/隐内容
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class JTextFieldHintListener implements FocusListener {
private String hintText;
private JTextField textField;
public JTextFieldHintListener(JTextField jTextField,String hintText) {
this.textField = jTextField;
this.hintText = hintText;
jTextField.setText(hintText); //默认直接显示
jTextField.setForeground(Color.GRAY);
}

@Override
public void focusGained(FocusEvent e) {
//获取焦点时,清空提示内容
String temp = textField.getText();
if(temp.equals(hintText)) {
textField.setText("");
textField.setForeground(Color.BLACK);
}

}

@Override
public void focusLost(FocusEvent e) {
//失去焦点时,没有输入内容,显示提示内容
String temp = textField.getText();
if(temp.equals("")) {
textField.setForeground(Color.GRAY);
textField.setText(hintText);
}

}
}

MainFrame类
点击显/隐内容
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
public class MainFrame extends javax.swing.JFrame {
// 把数据从文件中读到单链表中去
String bookPath="./Book21.txt";
String borrProPath="./BorrList.txt";
SingleLinkList book=UtilClass.readUtilB(bookPath);
SingleLinkList list=UtilClass.readUtilP("./a.txt");
SingleLinkList borrPro=UtilClass.readUtilBorrP(borrProPath);
/**
* Creates new form MainFrame
*/
public MainFrame() {
initComponents();
}

/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {

jLabel1 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jSeparator1 = new javax.swing.JSeparator();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jTextField3 = new javax.swing.JTextField();
jTextField4 = new javax.swing.JTextField();
jTextField5 = new javax.swing.JTextField();
jTextField6 = new javax.swing.JTextField();
jTextField9 = new javax.swing.JTextField();
jComboBox1 = new javax.swing.JComboBox<>();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
jButton6 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jButton7 = new javax.swing.JButton();
jTextField7 = new javax.swing.JTextField();
jTextField8 = new javax.swing.JTextField();
jLabel8 = new javax.swing.JLabel();
jTextField10 = new javax.swing.JTextField();
jTextField11 = new javax.swing.JTextField();
jButton8 = new javax.swing.JButton();
jButton9 = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("This system was designed by Cheerui");
addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
formMouseClicked(evt);
}
});

jLabel1.setFont(new java.awt.Font("黑体", 1, 24)); // NOI18N
jLabel1.setText("图书管理系统");

jButton1.setText("登录");
jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton1MouseClicked(evt);
}
});

jButton2.setText("注册");
jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton2MouseClicked(evt);
}
});

jLabel2.setFont(new java.awt.Font("黑体", 0, 14)); // NOI18N
jLabel2.setText("添加图书:");

jLabel3.setFont(new java.awt.Font("黑体", 0, 14)); // NOI18N
jLabel3.setText("删除图书:");

jLabel4.setFont(new java.awt.Font("黑体", 0, 14)); // NOI18N
jLabel4.setText("查询图书:");

jLabel5.setFont(new java.awt.Font("黑体", 0, 14)); // NOI18N
jLabel5.setText("统计图书:");

// jTextField1.setText("书 籍 名 称");
jTextField1.addFocusListener(new JTextFieldHintListener(jTextField1, "书 籍 名 称"));
jTextField1.setName("ABName"); // NOI18N

// jTextField2.setText("书 籍 编 号");
jTextField2.addFocusListener(new JTextFieldHintListener(jTextField2, "书 籍 编号"));
jTextField2.setName("ABId"); // NOI18N

// jTextField3.setText("书 籍 单 价");
jTextField3.addFocusListener(new JTextFieldHintListener(jTextField3, "书 籍 单 价"));
jTextField3.setName("ABPrice"); // NOI18N

// jTextField4.setText("书 籍 作 者");
jTextField4.addFocusListener(new JTextFieldHintListener(jTextField4, "书 籍 作 者"));
jTextField4.setName("ABAuthor"); // NOI18N

// jTextField5.setText("书 籍 总 量");
jTextField5.addFocusListener(new JTextFieldHintListener(jTextField5, "书 籍 总 量"));
jTextField5.setName("ABNum"); // NOI18N

// jTextField6.setText("书 籍 名 称");
jTextField6.addFocusListener(new JTextFieldHintListener(jTextField6, "书 籍 名 称"));
jTextField6.setName("DBName"); // NOI18N

// jTextField9.setText("书 籍 名 称");
jTextField9.addFocusListener(new JTextFieldHintListener(jTextField9, "书 籍 名 称"));
jTextField9.setName("SBName"); // NOI18N

jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "库 存", "借出量" }));
jComboBox1.setName("Sta"); // NOI18N

jButton3.setText("添加");
jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton3MouseClicked(evt);
}
});

jButton4.setText("删除");
jButton4.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton4MouseClicked(evt);
}
});

jButton5.setText("查询");
jButton5.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton5MouseClicked(evt);
}
});

jButton6.setText("统计");
jButton6.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton6MouseClicked(evt);
}
});

jTextArea1.setEditable(false);
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jTextArea1.setName("textarea"); // NOI18N
jScrollPane1.setViewportView(jTextArea1);

jLabel6.setFont(new java.awt.Font("黑体", 0, 14)); // NOI18N
jLabel6.setText("借 书:");

jLabel7.setFont(new java.awt.Font("黑体", 0, 14)); // NOI18N
jLabel7.setText("还 书:");

jButton7.setFont(new java.awt.Font("黑体", 0, 14)); // NOI18N
jButton7.setText("查询所有图书");
jButton7.setName("select"); // NOI18N
jButton7.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton7MouseClicked(evt);
}
});
jButton7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton7ActionPerformed(evt);
}
});

// jTextField7.setText("书 籍 名 称");
jTextField7.addFocusListener(new JTextFieldHintListener(jTextField7, "书 籍 名 称"));
jTextField7.setName("BBName"); // NOI18N

// jTextField8.setText("借阅人姓名");
jTextField8.addFocusListener(new JTextFieldHintListener(jTextField8, "借阅人姓名"));
jTextField8.setName("RPName"); // NOI18N

jLabel8.setFont(new java.awt.Font("黑体", 0, 14)); // NOI18N
jLabel8.setText("当前用户:");

jTextField10.setEditable(false);
jTextField10.setText("尚未登录");

jTextField11.setText("书籍借出量");
jTextField11.addFocusListener(new JTextFieldHintListener(jTextField11, "书籍借出量"));
jTextField11.setName("ABBrrow"); // NOI18N

jButton8.setText("确定");
jButton8.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton8MouseClicked(evt);
}
});

jButton9.setText("确定");
jButton9.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton9MouseClicked(evt);
}
});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel8)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextField10, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel1)
.addGap(91, 91, 91)
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton2))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(jButton7)))
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jTextField11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
.addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel7)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jButton8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTextField9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(13, 13, 13)
.addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(jLabel5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(17, 17, 17)
.addComponent(jButton6))))
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING)))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField10, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2)
.addComponent(jLabel8))
.addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jLabel2))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton3)
.addComponent(jTextField11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(15, 15, 15)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton4))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(jTextField9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton5))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton6))
.addGap(27, 27, 27)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel6)
.addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton8))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel7)
.addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton9))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE)
.addComponent(jButton7)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);

pack();
}// </editor-fold>//GEN-END:initComponents

private void jButton6MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton6MouseClicked
// TODO add your handling code here:
String str;
if(((String)jComboBox1.getSelectedItem()).equals("库 存"))
{

str=UtilClass.staInven(book);
jTextArea1.setText(str);
}else if(((String)jComboBox1.getSelectedItem()).equals("借出量"))
{
str=UtilClass.staRent(book);
jTextArea1.setText(str);
}
}//GEN-LAST:event_jButton6MouseClicked

private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
NewJFrame jFrame=new NewJFrame();
jFrame.setVisible(rootPaneCheckingEnabled);

}

private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
NewJFrame jFrame=new NewJFrame();
jFrame.setVisible(rootPaneCheckingEnabled);

}

private void jButton7MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
StringBuffer strb = book.printList();
String str =new String(strb);
System.out.println(str);
jTextArea1.setText(str);
}

private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:

}

private void formMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
}

private void jButton9MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
if(jTextField10.getText().equals("尚未登录"))
{
JOptionPane.showMessageDialog(null, "登录后方可还书");
}else {
String str =jTextField8.getText();
StringBuffer strb= UtilClass.borrProQ(str,borrPro,book,bookPath,borrProPath);
String str1=new String(strb);
jTextArea1.setText(str1);
}
}

private void jButton3MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
UtilClass.addBook(jTextField1.getText(), Integer.parseInt(jTextField2.getText()), jTextField3.getText(), jTextField4.getText(), Integer.parseInt(jTextField5.getText()), Integer.parseInt(jTextField11.getText()), bookPath, book);
}

private void jButton4MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
UtilClass.deleteBook(jTextField6.getText(),bookPath, book);
}

private void jButton8MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
if(jTextField10.getText().equals("尚未登录"))
{
JOptionPane.showMessageDialog(null, "登录后方可借书");
}else{
UtilClass.rentBook(jTextField7.getText(), book, borrProPath,bookPath,borrPro);
}
}

private void jButton5MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
StringBuffer strb = UtilClass.fuzzyQ(jTextField9.getText(), book);
String str =new String(strb);
jTextArea1.setText(str);
}




/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>

/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MainFrame().setVisible(true);
}
});
}

// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton6;
private javax.swing.JButton jButton7;
private javax.swing.JButton jButton8;
private javax.swing.JButton jButton9;
private javax.swing.JComboBox<String> jComboBox1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextField jTextField1;
public static javax.swing.JTextField jTextField10;
private javax.swing.JTextField jTextField11;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JTextField jTextField4;
private javax.swing.JTextField jTextField5;
private javax.swing.JTextField jTextField6;
public static javax.swing.JTextField jTextField7;
private javax.swing.JTextField jTextField8;
private javax.swing.JTextField jTextField9;
// End of variables declaration//GEN-END:variables
}

测试结果

放几个测试结果
界面1
界面2
界面3
界面4
界面4

项目代码下载(包括数据文件)

项目代码

咦~~~~ 这是嘛呀!!!
0%