Skip to content

Commit ac5f38a

Browse files
committed
fix bugs: Change "Refresh" button --> "All"
1 parent de01ef6 commit ac5f38a

File tree

1 file changed

+100
-61
lines changed

1 file changed

+100
-61
lines changed

src/Library/FrmBooksManagement.java

Lines changed: 100 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ public class FrmBooksManagement extends JFrame {
2323
private final String[] cb_Status = { "Rented", "Not rented" };
2424
private JComboBox tStatus = new JComboBox(cb_Status);
2525

26+
// Record current what type of view will be shown in book table
27+
private enum ViewBookType {
28+
All,
29+
Rented,
30+
NotRented,
31+
Overdue
32+
}
33+
34+
private ViewBookType viewBookType=ViewBookType.All;
35+
2636
private JLabel lStatus;
2737
JLabel lISBN;
2838
JTextField tISBN;
@@ -39,15 +49,34 @@ public class FrmBooksManagement extends JFrame {
3949
JButton btnRented;
4050
JButton btnNotRented;
4151
JButton btnOverDue;
42-
JButton btnRefresh;
52+
JButton btnAll;
4353

4454
public void Refresh(){
4555
int j = table.getRowCount();
4656
for (int i = 0; i < j; i++) {
4757
dtm.removeRow(0);
4858
}
49-
ArrayList<Book> books = FrmBooksManagement.this.library
50-
.showBookList_all();
59+
ArrayList<Book> books = null;
60+
61+
// according to current type of view
62+
switch (viewBookType) {
63+
case All:
64+
books= FrmBooksManagement.this.library.showBookList_all();
65+
break;
66+
case Rented:
67+
books=FrmBooksManagement.this.library.showBookList_rented();
68+
break;
69+
case NotRented:
70+
books=FrmBooksManagement.this.library.showBookList_remainder();
71+
break;
72+
case Overdue:
73+
books=FrmBooksManagement.this.library.showBookList_overdue();
74+
break;
75+
default:
76+
books=FrmBooksManagement.this.library.showBookList_all();
77+
break;
78+
}
79+
5180
int nBook = books.size();
5281

5382
for (int i = 0; i < nBook; i++) {
@@ -106,19 +135,24 @@ public FrmBooksManagement(Library lib) {
106135

107136
btnRented = new JButton("Rented");
108137
btnRented.setVisible(true);
109-
btnRented.setBounds(110, 15, 120, 30);
138+
btnRented.setBounds(50, 15, 120, 30);
110139
this.add(btnRented);
111140

112141
btnNotRented = new JButton("Not Rented");
113142
btnNotRented.setVisible(true);
114-
btnNotRented.setBounds(270, 15, 120, 30);
143+
btnNotRented.setBounds(210, 15, 120, 30);
115144
this.add(btnNotRented);
116145

117146
btnOverDue = new JButton("OverDue");
118147
btnOverDue.setVisible(true);
119-
btnOverDue.setBounds(430, 15, 120, 30);
148+
btnOverDue.setBounds(370, 15, 120, 30);
120149
this.add(btnOverDue);
121-
150+
151+
btnAll = new JButton("All");
152+
btnAll.setVisible(true);
153+
btnAll.setBounds(530, 15, 120, 30);
154+
this.add(btnAll);
155+
122156
lStatus = new JLabel();
123157
lStatus.setVisible(true);
124158
lStatus.setText("Status:");
@@ -189,81 +223,86 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
189223
Refresh();
190224
}
191225
});
192-
193-
btnRefresh = new JButton("Refresh");
194-
btnRefresh.setVisible(true);
195-
btnRefresh.setBounds(250, 470, 120, 30);
196-
this.add(btnRefresh);
197-
198226

199227

200-
btnRefresh.addActionListener(new java.awt.event.ActionListener() {
228+
btnAll.addActionListener(new java.awt.event.ActionListener() {
201229
public void actionPerformed(java.awt.event.ActionEvent evt) {
202-
int j = table.getRowCount();
203-
for (int i = 0; i < j; i++) {
204-
dtm.removeRow(0);
205-
}
206-
ArrayList<Book> books = FrmBooksManagement.this.library
207-
.showBookList_all();
208-
int nBook = books.size();
209-
210-
for (int i = 0; i < nBook; i++) {
211-
dtm.addRow(createBookTableRowData(books.get(i)));
212-
}
230+
//modify by Li Huang 2014.8.15
231+
// int j = table.getRowCount();
232+
// for (int i = 0; i < j; i++) {
233+
// dtm.removeRow(0);
234+
// }
235+
// ArrayList<Book> books = FrmBooksManagement.this.library
236+
// .showBookList_all();
237+
// int nBook = books.size();
238+
//
239+
// for (int i = 0; i < nBook; i++) {
240+
// dtm.addRow(createBookTableRowData(books.get(i)));
241+
// }
242+
viewBookType = ViewBookType.All;
243+
Refresh();
213244
}
214245
});
215246

216247

217248

218249
btnRented.addActionListener(new java.awt.event.ActionListener() {
219250
public void actionPerformed(java.awt.event.ActionEvent evt) {
220-
int j = table.getRowCount();
221-
for (int i = 0; i < j; i++) {
222-
dtm.removeRow(0);
223-
}
224-
ArrayList<Book> books = FrmBooksManagement.this.library
225-
.showBookList_all();
226-
int nBook = books.size();
227-
228-
for (int i = 0; i < nBook; i++) {
229-
if(!books.get(i).isRented()){continue;}
230-
dtm.addRow(createBookTableRowData(books.get(i)));
231-
}
251+
//modify by Li Huang 2014.8.15
252+
// int j = table.getRowCount();
253+
// for (int i = 0; i < j; i++) {
254+
// dtm.removeRow(0);
255+
// }
256+
// ArrayList<Book> books = FrmBooksManagement.this.library
257+
// .showBookList_all();
258+
// int nBook = books.size();
259+
//
260+
// for (int i = 0; i < nBook; i++) {
261+
// if(!books.get(i).isRented()){continue;}
262+
// dtm.addRow(createBookTableRowData(books.get(i)));
263+
// }
264+
viewBookType = ViewBookType.Rented;
265+
Refresh();
232266
}
233267
});
234268

235269
btnNotRented.addActionListener(new java.awt.event.ActionListener() {
236270
public void actionPerformed(java.awt.event.ActionEvent evt) {
237-
int j = table.getRowCount();
238-
for (int i = 0; i < j; i++) {
239-
dtm.removeRow(0);
240-
}
241-
ArrayList<Book> books = FrmBooksManagement.this.library
242-
.showBookList_all();
243-
int nBook = books.size();
244-
245-
for (int i = 0; i < nBook; i++) {
246-
if(books.get(i).isRented()){continue;}
247-
dtm.addRow(createBookTableRowData(books.get(i)));
248-
}
271+
//modify by Li Huang 2014.8.15
272+
// int j = table.getRowCount();
273+
// for (int i = 0; i < j; i++) {
274+
// dtm.removeRow(0);
275+
// }
276+
// ArrayList<Book> books = FrmBooksManagement.this.library
277+
// .showBookList_all();
278+
// int nBook = books.size();
279+
//
280+
// for (int i = 0; i < nBook; i++) {
281+
// if(books.get(i).isRented()){continue;}
282+
// dtm.addRow(createBookTableRowData(books.get(i)));
283+
// }
284+
viewBookType = ViewBookType.NotRented;
285+
Refresh();
249286
}
250287

251288
});
252289

253290
btnOverDue.addActionListener(new java.awt.event.ActionListener() {
254291
public void actionPerformed(java.awt.event.ActionEvent evt) {
255-
int j = table.getRowCount();
256-
for (int i = 0; i < j; i++) {
257-
dtm.removeRow(0);
258-
}
259-
ArrayList<Book> books = FrmBooksManagement.this.library
260-
.showBookList_all();
261-
int nBook = books.size();
262-
int o_size = library.showBookList_overdue().size();
263-
for (int i = 0; i < o_size; i++) {
264-
// if(books.get(i).isRented()){continue;}
265-
dtm.addRow(createBookTableRowData(library.showBookList_overdue().get(i)));
266-
}
292+
// int j = table.getRowCount();
293+
// for (int i = 0; i < j; i++) {
294+
// dtm.removeRow(0);
295+
// }
296+
// ArrayList<Book> books = FrmBooksManagement.this.library
297+
// .showBookList_all();
298+
// int nBook = books.size();
299+
// int o_size = library.showBookList_overdue().size();
300+
// for (int i = 0; i < o_size; i++) {
301+
//// if(books.get(i).isRented()){continue;}
302+
// dtm.addRow(createBookTableRowData(library.showBookList_overdue().get(i)));
303+
// }
304+
viewBookType = ViewBookType.Overdue;
305+
Refresh();
267306
}
268307
});
269308

0 commit comments

Comments
 (0)