-
Notifications
You must be signed in to change notification settings - Fork 4
/
ChequingHistoryPage.java
391 lines (366 loc) · 15.7 KB
/
ChequingHistoryPage.java
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
import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.util.ArrayList;
/**
* This class is the graphical implementation of the customer's chequing account transaction history
* It displays the last 6 transactions the customer did with their chequing account.
*/
public class ChequingHistoryPage extends JFrame implements ActionListener
{
static final int WIDTH = 1920;
static final int LENGTH = 1080;
BankAutomated BA;
HomePage home;
CA customer;
private final JButton backToHome;
/**
* ChequingHistoryPage Constructor. This constructor creates all the frame specifications for when the customer
* clicks on their chequing account (i.e., buttons, display setup, etc.). It retrieves the customer's latest
* 6 chequing transaction and formats and displays them.
* @param home HomePage object to return to when the user wants to
* @param BA BankAutomated object to process the logout if the user exits the system
* @param customer CA object, the customer that is logged in
*/
public ChequingHistoryPage(HomePage home, BankAutomated BA, CA customer)
{
this.setTitle("Chequing History");
this.setLayout(null);
this.home = home;
this.BA = BA;
this.customer = customer;
Font labels = new Font("Raleway", Font.PLAIN, 22);
Border emptyBorder = BorderFactory.createEmptyBorder();
Border border = BorderFactory.createLineBorder(Color.black, 2);
Color bg = new Color(214, 215, 215);
ArrayList<JTextArea> blocks = new ArrayList<>();
blocks.add(new JTextArea()); blocks.add(new JTextArea()); blocks.add(new JTextArea());
blocks.add(new JTextArea()); blocks.add(new JTextArea()); blocks.add(new JTextArea());
int i = 0;
if (customer.getSavingsHist().size() != 0)
{
for (Transaction transaction : customer.getChequingHist())
{
if (transaction.getSender().equals(customer.getEmail()) && transaction.getAccountFrom().equals("Chequing"))
{
String type = "E-Transfer";
String id = String.valueOf(transaction.getId());
String receiverEmail = transaction.getReceiver();
String amount = "$ -" + transaction.getAmount();
String remaining = "$ " + Math.round(transaction.getSenderRemaining()*100.0)/100.0;
JTextArea trans = blocks.get(i);
trans.setText(" Transaction ID: " + id + "\n Receiver (Email): " + receiverEmail +
"\n Amount: " + amount + "\n Remaining Balance: " + remaining + "\n Type: " + type);
trans.setBackground(Color.white);
trans.setBorder(border);
trans.setEditable(false);
trans.setFont(labels);
if (i == 0)
{
trans.setBounds(35, 150, 600, 150);
}
else if (i == 1)
{
trans.setBounds(635, 150, 600, 150);
}
else if (i == 2)
{
trans.setBounds(35, 300, 600, 150);
}
else if (i == 3)
{
trans.setBounds(635, 300, 600, 150);
}
else if (i == 4)
{
trans.setBounds(35, 450, 600, 150);
}
else if (i == 5)
{
trans.setBounds(635, 450, 600, 150);
}
this.add(trans);
}
else if (transaction.getSender().equals(customer.getFirstName() + " " + customer.getLastName()) && transaction.getAccountFrom().equals("Chequing"))
{
String type = "Bank Transfer";
String id = String.valueOf(transaction.getId());
String receiverAcc = transaction.getReceiver();
String amount = "$ -" + transaction.getAmount();
String remaining = "$ " + Math.round(transaction.getSenderRemaining()*100.0)/100.0;
JTextArea trans = blocks.get(i);
trans.setText(" Transaction ID: " + id + "\n Receiver (Acc#): " + receiverAcc +
"\n Amount: " + amount + "\n Remaining Balance: " + remaining + "\n Type: " + type);
trans.setBackground(Color.white);
trans.setBorder(border);
trans.setEditable(false);
trans.setFont(labels);
if (i == 0)
{
trans.setBounds(35, 150, 600, 150);
}
else if (i == 1)
{
trans.setBounds(635, 150, 600, 150);
}
else if (i == 2)
{
trans.setBounds(35, 300, 600, 150);
}
else if (i == 3)
{
trans.setBounds(635, 300, 600, 150);
}
else if (i == 4)
{
trans.setBounds(35, 450, 600, 150);
}
else if (i == 5)
{
trans.setBounds(635, 450, 600, 150);
}
this.add(trans);
}
else if (transaction.getSender().equals("Chequing"))
{
String type = "Fund Transfer";
String id = String.valueOf(transaction.getId());
String fromTo = "Chequing to Savings";
String amount = "$ -" + transaction.getAmount();
String remaining = "$ " + Math.round(transaction.getSenderRemaining() * 100.0)/100.0;
JTextArea trans = blocks.get(i);
trans.setText(" Transaction ID: " + id + "\n From, To: " + fromTo +
"\n Amount: " + amount + "\n Remaining Balance: " + remaining + "\n Type: " + type);
trans.setBackground(Color.white);
trans.setBorder(border);
trans.setEditable(false);
trans.setFont(labels);
if (i == 0)
{
trans.setBounds(35, 150, 600, 150);
}
else if (i == 1)
{
trans.setBounds(635, 150, 600, 150);
}
else if (i == 2)
{
trans.setBounds(35, 300, 600, 150);
}
else if (i == 3)
{
trans.setBounds(635, 300, 600, 150);
}
else if (i == 4)
{
trans.setBounds(35, 450, 600, 150);
}
else if (i == 5)
{
trans.setBounds(635, 450, 600, 150);
}
this.add(trans);
}
else if (transaction.getSender().equals("Savings"))
{
String type = "Fund Transfer";
String id = String.valueOf(transaction.getId());
String fromTo = "Savings to Chequing";
String amount = "$ " + transaction.getAmount();
String remaining = "$ " + Math.round(transaction.getReceiverRemaining()*100.0)/100.0;
JTextArea trans = blocks.get(i);
trans.setText(" Transaction ID: " + id + "\n From, To: " + fromTo +
"\n Amount: " + amount + "\n Remaining Balance: " + remaining + "\n Type: " + type);
trans.setBackground(Color.white);
trans.setBorder(border);
trans.setEditable(false);
trans.setFont(labels);
if (i == 0)
{
trans.setBounds(35, 150, 600, 150);
}
else if (i == 1)
{
trans.setBounds(635, 150, 600, 150);
}
else if (i == 2)
{
trans.setBounds(35, 300, 600, 150);
}
else if (i == 3)
{
trans.setBounds(635, 300, 600, 150);
}
else if (i == 4)
{
trans.setBounds(35, 450, 600, 150);
}
else if (i == 5)
{
trans.setBounds(635, 450, 600, 150);
}
this.add(trans);
}
else if (transaction.getReceiver().equals(customer.getBankNumber()))
{
String type = "Bank Transfer";
String id = String.valueOf(transaction.getId());
String senderName = transaction.getSender();
String amount = "$ " + transaction.getAmount();
String remaining = "$ " + Math.round(transaction.getReceiverRemaining()*100.0)/100.0;
JTextArea trans = blocks.get(i);
trans.setText(" Transaction ID: " + id + "\n Sender's Name: " + senderName +
"\n Amount: " + amount + "\n Remaining Balance: " + remaining + "\n Type: " + type);
trans.setBackground(Color.white);
trans.setBorder(border);
trans.setEditable(false);
trans.setFont(labels);
if (i == 0)
{
trans.setBounds(35, 150, 600, 150);
}
else if (i == 1)
{
trans.setBounds(635, 150, 600, 150);
}
else if (i == 2)
{
trans.setBounds(35, 300, 600, 150);
}
else if (i == 3)
{
trans.setBounds(635, 300, 600, 150);
}
else if (i == 4)
{
trans.setBounds(35, 450, 600, 150);
}
else if (i == 5)
{
trans.setBounds(635, 450, 600, 150);
}
this.add(trans);
}
else if (transaction.getReceiver().equals(customer.getEmail()))
{
String type = "E-Transfer";
String id = String.valueOf(transaction.getId());
String senderName = transaction.getSender();
String amount = "$ " + transaction.getAmount();
String remaining = "$ " + Math.round(transaction.getReceiverRemaining()*100.0)/100.0;
JTextArea trans = blocks.get(i);
trans.setText(" Transaction ID: " + id + "\n Sender's Email: " + senderName +
"\n Amount: " + amount + "\n Remaining Balance: " + remaining + "\n Type: " + type);
trans.setBackground(Color.white);
trans.setBorder(border);
trans.setEditable(false);
trans.setFont(labels);
if (i == 0)
{
trans.setBounds(35, 150, 600, 150);
}
else if (i == 1)
{
trans.setBounds(635, 150, 600, 150);
}
else if (i == 2)
{
trans.setBounds(35, 300, 600, 150);
}
else if (i == 3)
{
trans.setBounds(635, 300, 600, 150);
}
else if (i == 4)
{
trans.setBounds(35, 450, 600, 150);
}
else if (i == 5)
{
trans.setBounds(635, 450, 600, 150);
}
this.add(trans);
}
i++;
if (i >= 6)
{
break;
}
}
}
else
{
JLabel noHist = new JLabel("No Transaction History");
noHist.setFont(new Font("Raleway", Font.BOLD, 50));
noHist.setBounds(375, 300, 700, 70);
this.add(noHist);
}
backToHome = new JButton("Back to Home");
backToHome.setFont(new Font("SansSerif", Font.PLAIN, 22));
backToHome.setBounds(450, 600, 350, 50);
backToHome.setBackground(Color.white);
backToHome.setForeground(new Color(57, 107, 170));
backToHome.setCursor(new Cursor(Cursor.HAND_CURSOR));
backToHome.setContentAreaFilled(false);
backToHome.setFocusPainted(false);
backToHome.setBorder(emptyBorder);
backToHome.setContentAreaFilled(false);
backToHome.addActionListener(this);
this.add(backToHome);
this.addWindowListener(new WindowEventHandler() {
@Override
public void windowClosing(WindowEvent evt) {
//BA.logout (logic.logout) would be called here
//Write all changes to the file
BA.logout();
Window[] windows = Window.getWindows();
for (Window window : windows) {
window.dispose();
}
System.exit(0);
}
});
this.getContentPane().setBackground(bg);
this.getRootPane().setDefaultButton(backToHome);
this.setSize(WIDTH, LENGTH);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(false);
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
}
/**
* paint method, overrides the JFrame paint method in order to allow for custom graphical design
* @param g Graphics object
*/
public void paint(Graphics g)
{
super.paint(g);
// Paint the background
Graphics2D g2 = (Graphics2D) g;
Color myRed = new Color(230, 30, 30);
Color myBlack = new Color(160, 32, 32);
GradientPaint redToBlack = new GradientPaint(0, 0, myRed, 0, 150, myBlack);
g2.setPaint(redToBlack);
g2.fillRect(0, 0, WIDTH+1, 150);
Font regFont = new Font("Raleway", Font.BOLD, 60);
g2.setFont(regFont);
g2.setColor(new Color(250, 185, 60));
g2.drawString("Chequing Transaction History", 25, 110);
}
/**
* actionPerformed method (implementing ActionListener). When the "Back To Home" button is clicked, it sends
* the customer back to their homepage.
* @param e ActionEvent object, which listens and keeps track of any button clicks
*/
@Override
public void actionPerformed(ActionEvent e)
{
// If the back to home button is pressed
if (e.getSource() == backToHome) {
this.setVisible(false);
home.setVisible(true);
}
}
}