-
Notifications
You must be signed in to change notification settings - Fork 0
/
ATM.java
585 lines (519 loc) · 28.1 KB
/
ATM.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
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
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.awt.Font;
import java.io.IOException;
import javax.swing.JOptionPane;
/**
*
* Modified by Param Mehta
*/
public class ATM extends javax.swing.JFrame {
/**
* Creates new form NewJFrame
*/
public ATM() {
initComponents();
setUsage();
}
private void setUsage(){
jB_depositInterest.setEnabled(false);
jTF_nameSearch.setEditable(false);
jTF_balanceSearch.setEditable(false);
jTA_output.setFont(new Font("Sans Serif", 1, 12));
jTA_output.setText("\n\nWelcome to \n\n Param's Federal Bank \n\nSearch for an account \nby number first");
}
/**
* 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">
private void initComponents() {
jTabbedPane1 = new javax.swing.JTabbedPane();
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jTF_accNumSearch = new javax.swing.JTextField();
jB_accNumSearch = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
jTF_nameSearch = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
jTF_balanceSearch = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
jTF_depWith = new javax.swing.JTextField();
jB_deposit = new javax.swing.JButton();
jB_withdraw = new javax.swing.JButton();
jB_depositInterest = new javax.swing.JButton();
jPanel4 = new javax.swing.JPanel();
jTF_findByName = new javax.swing.JTextField();
jB_findByName = new javax.swing.JButton();
jTF_findByAccNum = new javax.swing.JTextField();
jB_findByAccNum = new javax.swing.JButton();
jSeparator1 = new javax.swing.JSeparator();
jLabel5 = new javax.swing.JLabel();
jTF_addName1 = new javax.swing.JTextField();
jTF_balance = new javax.swing.JTextField();
jTF_addAccNum = new javax.swing.JTextField();
jCB_isChecking = new javax.swing.JCheckBox();
jB_addAccount = new javax.swing.JButton();
jPanel5 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
jTA_output = new javax.swing.JTextArea();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("Account Number:");
jTF_accNumSearch.setText("AccNum");
jB_accNumSearch.setText("Find");
jB_accNumSearch.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jB_accNumSearchActionPerformed(evt);
}
});
jLabel2.setText("Name");
jLabel3.setText("Balance");
jLabel4.setText("Deposit/Withdraw Amount");
jTF_depWith.setText("0.00");
jB_deposit.setText("Deposit");
jB_deposit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jB_depositActionPerformed(evt);
}
});
jB_withdraw.setText("Withdraw");
jB_withdraw.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jB_withdrawActionPerformed(evt);
}
});
jB_depositInterest.setText("Deposit Interest");
jB_depositInterest.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jB_depositInterestActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jB_depositInterest, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jTF_depWith)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(jLabel2)
.addGap(14, 14, 14))
.addComponent(jLabel3))
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jTF_nameSearch, javax.swing.GroupLayout.DEFAULT_SIZE, 203, Short.MAX_VALUE)
.addComponent(jTF_balanceSearch))
.addGap(3, 3, 3))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addComponent(jB_deposit, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jB_withdraw, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jTF_accNumSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jB_accNumSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jLabel4))
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTF_accNumSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jB_accNumSearch))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTF_nameSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTF_balanceSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3))
.addGap(38, 38, 38)
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTF_depWith, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jB_withdraw)
.addComponent(jB_deposit))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jB_depositInterest, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jTabbedPane1.addTab("Transactions", jPanel1);
jTF_findByName.setText("Search By Name");
jB_findByName.setText("Find");
jB_findByName.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jB_findByNameActionPerformed(evt);
}
});
jTF_findByAccNum.setText("Search By Account Number");
jB_findByAccNum.setText("Find");
jB_findByAccNum.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jB_findByAccNumActionPerformed(evt);
}
});
jLabel5.setText("Add Accounts");
jTF_addName1.setText("Name");
jTF_balance.setText("Balance");
jTF_addAccNum.setText("Account Number");
jCB_isChecking.setText("Checking Account");
jCB_isChecking.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jCB_isCheckingActionPerformed(evt);
}
});
jB_addAccount.setText("Add Account");
jB_addAccount.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jB_addAccountActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
jPanel4.setLayout(jPanel4Layout);
jPanel4Layout.setHorizontalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addComponent(jTF_findByName)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jB_findByName))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
.addComponent(jTF_findByAccNum, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jB_findByAccNum))
.addComponent(jSeparator1)
.addComponent(jTF_addName1)
.addComponent(jTF_balance)
.addComponent(jTF_addAccNum)
.addGroup(jPanel4Layout.createSequentialGroup()
.addComponent(jLabel5)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(jPanel4Layout.createSequentialGroup()
.addComponent(jCB_isChecking)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jB_addAccount, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addContainerGap())
);
jPanel4Layout.setVerticalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel4Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTF_findByName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jB_findByName))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTF_findByAccNum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jB_findByAccNum))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jTF_addName1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jTF_addAccNum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jTF_balance, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jCB_isChecking)
.addComponent(jB_addAccount))
.addContainerGap(42, Short.MAX_VALUE))
);
jTabbedPane1.addTab("Add/Search Accounts", jPanel4);
jTA_output.setColumns(20);
jTA_output.setRows(5);
jScrollPane1.setViewportView(jTA_output);
javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
jPanel5.setLayout(jPanel5Layout);
jPanel5Layout.setHorizontalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 249, Short.MAX_VALUE)
);
jPanel5Layout.setVerticalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1)
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 269, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE)
.addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jTabbedPane1)
.addGap(26, 26, 26))
.addGroup(layout.createSequentialGroup()
.addGap(35, 35, 35)
.addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addContainerGap())
);
pack();
}// </editor-fold>
private void jB_depositInterestActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
int accNum = Integer.parseInt(jTF_accNumSearch.getText().trim());
int loc = bank.findAccount(accNum);
Account acc = bank.getAccounts().get(loc);
if(acc instanceof CheckingAccount){
String output = "Previous Account Details: \n";
output += bank.displayAccount(accNum);
((CheckingAccount) acc).depositInterest();
output += "\n\nAccount Details after Transaction: \n";
output += bank.displayAccount(accNum);
jTA_output.setText(output);
jTF_nameSearch.setText("");
jTF_balanceSearch.setText("");
jTF_accNumSearch.setText("");
jB_depositInterest.setEnabled(false);
}
}catch(Exception e){
JOptionPane.showMessageDialog(null, "Unknown Error" );
}
}
private void jB_findByNameActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
String owner = jTF_findByName.getText().trim();
int loc = bank.findAccount(owner);
if(loc == -1){
JOptionPane.showMessageDialog(null, "Account Does Not Exist");
jTF_findByName.setText("Search By Name");
jTF_findByAccNum.setText("Search by Account Number");
}
else{
String output = Util.splitAccounts(bank.displayAccounts(owner));
jTA_output.setText(output);
jTF_findByName.setText("Search By Name");
jTF_findByAccNum.setText("Search by Account Number");
}
}catch(Exception e){
JOptionPane.showMessageDialog(null, "Account Number Must Be An Integer");
}
}
private void jB_accNumSearchActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
int accNum = Integer.parseInt(jTF_accNumSearch.getText().trim());
int loc = bank.findAccount(accNum);
if(loc == -1)
JOptionPane.showMessageDialog(null, "Account Does Not Exits");
else{
Account acc = bank.getAccounts().get(loc);
jTF_nameSearch.setText(acc.getOwner());
jTF_balanceSearch.setText(String.valueOf(acc.getBalance()));
if(acc instanceof CheckingAccount){
jB_depositInterest.setEnabled(true);
}
else{
jB_depositInterest.setEnabled(false);
}
}
}catch(Exception e){
JOptionPane.showMessageDialog(null, "Only Integer Input Allowed");
jTF_nameSearch.setText("");
jTF_balanceSearch.setText("");
}
}
private void jB_depositActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
double amount = Double.parseDouble(jTF_depWith.getText().trim());
int accNum = Integer.parseInt(jTF_accNumSearch.getText().trim());
int loc = bank.findAccount(accNum);
if(loc == -1)
JOptionPane.showMessageDialog(null, "Account Does Not Exits");
else{
Account acc = bank.getAccounts().get(loc);
String output = "Previous Account Details: \n";
output += bank.displayAccount(accNum);
acc.deposit(amount);
output += "\n\nAccount Details after Transaction: \n";
output += bank.displayAccount(accNum);
jTA_output.setText(output);
}
}catch(Exception e){
JOptionPane.showMessageDialog(null, "Only Double Input Allowed");
jTF_nameSearch.setText("");
jTF_balanceSearch.setText("");
}
}
private void jB_withdrawActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
double amount = Double.parseDouble(jTF_depWith.getText().trim());
int accNum = Integer.parseInt(jTF_accNumSearch.getText().trim());
int loc = bank.findAccount(accNum);
if(loc == -1)
JOptionPane.showMessageDialog(null, "Account Does Not Exits");
else{
Account acc = bank.getAccounts().get(loc);
String output = "Previous Account Details: \n";
output += bank.displayAccount(accNum);
if(acc.withdraw(amount) != -1){
output += "\n\nAccount Details after Transaction: \n";
output += bank.displayAccount(accNum);
jTA_output.setText(output);
}
else{
JOptionPane.showMessageDialog(null, "Over Drawn");
}
}
}catch(Exception e){
JOptionPane.showMessageDialog(null, "Only Double Input Allowed");
jTF_nameSearch.setText("");
jTF_balanceSearch.setText("");
}
}
private void jB_findByAccNumActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
int accNum = Integer.parseInt(jTF_findByAccNum.getText().trim());
int loc = bank.findAccount(accNum);
if(loc == -1){
JOptionPane.showMessageDialog(null, "Account Does Not Exist");
jTF_findByName.setText("Search By Name");
jTF_findByAccNum.setText("Search by Account Number");
}
else{
jTA_output.setText(bank.displayAccount(accNum));
jTF_findByName.setText("Search By Name");
jTF_findByAccNum.setText("Search by Account Number");
}
}catch(Exception e){
JOptionPane.showMessageDialog(null, "Account Number Must Be An Integer");
}
}
private void jB_addAccountActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
String name = jTF_addName1.getText().trim();
int accNum = Integer.parseInt(jTF_addAccNum.getText().trim());
double bal = Double.parseDouble(jTF_balance.getText().trim());
boolean isCheck = jCB_isChecking.isSelected();
bank.addAccount(name, accNum, bal, isCheck);
jTF_addName1.setText("Name");
jTF_addAccNum.setText("Account Number");
jTF_balance.setText("Balance");
jCB_isChecking.setEnabled(false);
}catch(Exception e){
JOptionPane.showMessageDialog(null, "Fieds to add account are not \nfilled in correctly");
jTF_addName1.setText("Name");
jTF_addAccNum.setText("Account Number");
jTF_balance.setText("Balance");
}
}
private void jCB_isCheckingActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int choice = JOptionPane.showConfirmDialog(null, "Confirm Checking", "Confirmation", 0);
if(choice == 1)
jCB_isChecking.setSelected(false);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
try {
bank = new Bank(Util.getAccounts());
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
/* 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(ATM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(ATM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(ATM.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(ATM.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 ATM().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jB_accNumSearch;
private javax.swing.JButton jB_addAccount;
private javax.swing.JButton jB_deposit;
private javax.swing.JButton jB_depositInterest;
private javax.swing.JButton jB_findByAccNum;
private javax.swing.JButton jB_findByName;
private javax.swing.JButton jB_withdraw;
private javax.swing.JCheckBox jCB_isChecking;
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.JPanel jPanel1;
private javax.swing.JPanel jPanel4;
private javax.swing.JPanel jPanel5;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JTextArea jTA_output;
private javax.swing.JTextField jTF_accNumSearch;
private javax.swing.JTextField jTF_addAccNum;
private javax.swing.JTextField jTF_addName1;
private javax.swing.JTextField jTF_balance;
private javax.swing.JTextField jTF_balanceSearch;
private javax.swing.JTextField jTF_depWith;
private javax.swing.JTextField jTF_findByAccNum;
private javax.swing.JTextField jTF_findByName;
private javax.swing.JTextField jTF_nameSearch;
private javax.swing.JTabbedPane jTabbedPane1;
// End of variables declaration
private static Bank bank;
}