Repository navigation
Expand file tree
/
Copy pathActPanel.java
More file actions
284 lines (257 loc) · 7.33 KB
/
Copy pathActPanel.java
File metadata and controls
284 lines (257 loc) · 7.33 KB
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
import java.awt.Dimension;
import java.awt.LayoutManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class ActPanel extends JPanel implements ActionListener{
/**
* This class represents the buttons to take actions
*/
private BookWindow wind;
private OrderDisplay ord;
private JButton del;
private JButton add;
private JButton ret;
private JButton chk;
private JTextField srch;
public static final String ordFile="orders.txt";
public ActPanel(BookWindow bw) {
// TODO Auto-generated constructor stub
super();
wind=bw;
init();
}
public void setord(OrderDisplay o){
ord=o;
}
public ActPanel(LayoutManager layout) {
super(layout);
// TODO Auto-generated constructor stub
}
public ActPanel(boolean isDoubleBuffered) {
super(isDoubleBuffered);
// TODO Auto-generated constructor stub
}
public ActPanel(LayoutManager layout, boolean isDoubleBuffered) {
super(layout, isDoubleBuffered);
// TODO Auto-generated constructor stub
}
/**
* This method sets up the display by initializing the buttons
*/
private void init(){
add=new JButton("Add New Book");
this.add(add);
add.addActionListener(this);
del=new JButton("Delete Book");
this.add(del);
del.addActionListener(this);
ret=new JButton("Return Book");
this.add(ret);
ret.addActionListener(this);
chk=new JButton("Check Out Book");
this.add(chk);
chk.addActionListener(this);
/*srch=new JTextField();
this.add(srch);
srch.setMinimumSize(new Dimension(100,10));
srch.addActionListener(this);*/
}
/**
* This method handles the buttons by bringing up windows to get information and calling the necessary methods.
*/
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==del){
try{
if(JOptionPane.YES_OPTION==JOptionPane.showConfirmDialog(wind, "Are you sure you want to delete " + wind.getSelection().getTitle()+"?")){
wind.removeListIndex(wind.getSelectionIndex());
}
}catch(Exception e1){
JOptionPane.showMessageDialog(wind,"Please select a book.");
}
}else if(e.getSource()==add){
String title=JOptionPane.showInputDialog(wind,"Enter the title:");
if(title==null){
return;
}
String ISBN = JOptionPane.showInputDialog(wind,"Enter ISBN:");
if(ISBN==null){
return;
}
double price=0;
int room=0;
int num=0;
Book.g grd=Book.g.NINE;
boolean go=true;
while(go){
try{
String str=JOptionPane.showInputDialog(wind,"Enter Price:");
if(str==null){
return;
}
price = Double.parseDouble(str);
go=false;
}catch(Exception e1){
JOptionPane.showMessageDialog(wind, "Please enter valid input.");
go=true;
}
}
go=true;
while(go){
try{
String str=JOptionPane.showInputDialog(wind,"Enter Storage room:");
if(str==null){
return;
}
room = Integer.parseInt(str);
go=false;
}catch(Exception e1){
JOptionPane.showMessageDialog(wind, "Please enter valid input.");
go=true;
}
}
go=true;
while(go){
try{
String str=JOptionPane.showInputDialog(wind,"Enter Number of books:");
if(str==null){
return;
}
num = Integer.parseInt(str);
go=false;
}catch(Exception e1){
JOptionPane.showMessageDialog(wind, "Please enter valid input.");
go=true;
}
}
go=true;
while(go){
try{
String grade=JOptionPane.showInputDialog(wind,"Enter grade:").toUpperCase();
go=false;
if(grade==null){
return;
}else{
grd=Book.g.valueOf(grade);
}
}catch(Exception e1){
JOptionPane.showMessageDialog(wind, "Please enter valid input.");
go=true;
}
}
wind.addBook(new Book(title,new BookOrder(room,num,""),num,price,ISBN,grd,0));
}else if(e.getSource()==chk){
int rm=0;
int num=0;
String teach="";
boolean go=true;
while(go)
{
try{
wind.getSelection();
String str=JOptionPane.showInputDialog("Please enter the room number.");
if(str==null){
return;
}else{
rm=Integer.parseInt(str);
}
go=false;
}catch(ArrayIndexOutOfBoundsException e1){
JOptionPane.showMessageDialog(wind,"Please select a book.");
return;
}catch(Exception e2){
JOptionPane.showMessageDialog(wind,"Please enter valid input.");
go=true;
}
}
go=true;
while(go)
{
try{
String str=JOptionPane.showInputDialog("Please enter the number of books being checked out.");
if(str==null){
return;
}else{
num=Integer.parseInt(str);
if(wind.getSelection().getStore().getNum()>num){
go=false;
}else{
go=true;
JOptionPane.showMessageDialog(wind,"There are not enough books in storage\nto fulfill this request.");
}
}
}catch(ArrayIndexOutOfBoundsException e1){
JOptionPane.showMessageDialog(wind,"Please select a book.");
return;
}catch(Exception e2){
JOptionPane.showMessageDialog(wind,"Please enter valid input.");
go=true;
}
}
go=true;
while(go)
{
try{
teach=JOptionPane.showInputDialog("Please enter the Teacher");
if(teach==null){
return;
}
go=false;
}catch(ArrayIndexOutOfBoundsException e1){
JOptionPane.showMessageDialog(wind,"Please select a book.");
return;
}catch(Exception e2){
JOptionPane.showMessageDialog(wind,"Please enter valid input.");
go=true;
}
}
wind.getSelection().addOrder(new BookOrder(rm,num,teach));
BookData.saveOrder(wind.ordFile, new OrderList(new BookOrder(rm,num,teach),wind.getSelection().getTitle()));
wind.getSelection().getStore().setNum(wind.getSelection().getStore().getNum()-num);;
}else if(e.getSource()==ret){
boolean go=true;
int num;
while(go)
{
try{
String str=JOptionPane.showInputDialog("Please enter the number of books being returned.");
if(str==null){
return;
}else if(ord.getSelection()!=null){
num=Integer.parseInt(str);
if(ord.getSelection().getNum()>=num){
go=false;
BookOrder or=new BookOrder(ord.getSelection().getRoom(),ord.getSelection().getNum(),ord.getSelection().getTeacher());
ord.getSelection().setNum(ord.getSelection().getNum()-num);
wind.getSelection().getStore().setNum(num+wind.getSelection().getStore().getNum());
if(ord.getSelection().getNum()==0){
ord.removeOrd();
BookData.zeroOrder(ordFile, new OrderList(or,wind.getSelection().getTitle()));
}else{
BookData.changeOrder(ordFile, new OrderList(or,wind.getSelection().getTitle()),new OrderList(ord.getSelection(),wind.getSelection().getTitle()));
}
}else{
go=true;
JOptionPane.showMessageDialog(wind,"There are not enough books in this order\nto fulfill this request.");
}
}else{
JOptionPane.showMessageDialog(wind,"Please select a book order.");
}
}catch(ArrayIndexOutOfBoundsException e1){
JOptionPane.showMessageDialog(wind,"Please select a book order.");
return;
}/*catch(Exception e2){
JOptionPane.showMessageDialog(wind,"Please enter valid input.");
go=true;
}*/
}
}else{
}
wind.refreshOrder();
}
}