-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankSystem.java
More file actions
730 lines (603 loc) · 23 KB
/
BankSystem.java
File metadata and controls
730 lines (603 loc) · 23 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
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
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;
import java.text.*;
import java.io.*;
import java.awt.PrintJob.*;
import javax.swing.plaf.metal.*;
public class BankSystem extends JFrame implements ActionListener, ItemListener {
//Main Place on Form where All Child Forms will Shown.
private JDesktopPane desktop = new JDesktopPane ();
//For Program's MenuBar.
private JMenuBar bar;
//All the Main Menu of the Program.
private JMenu mnuFile, mnuEdit, mnuView, mnuOpt, mnuWin, mnuHelp;
private JMenuItem addNew, printRec, end; //File Menu Options.
private JMenuItem deposit, withdraw, delRec, search, searchName; //Edit Menu Options.
private JMenuItem oneByOne, allCustomer; //View Menu Options.
private JMenuItem change, style, theme; //Option Menu Options.
private JMenuItem close, closeAll; //Window Menu Options.
private JMenuItem content, keyHelp, about; //Help Menu Options.
//PopupMenu of Program.
private JPopupMenu popMenu = new JPopupMenu ();
//MenuItems for PopupMenu of the Program.
private JMenuItem open, report, dep, with, del, find, all;
//For Program's ToolBar.
private JToolBar toolBar;
//For ToolBar's Button.
private JButton btnNew, btnDep, btnWith, btnRec, btnDel, btnSrch, btnHelp, btnKey;
//Main Form StatusBar where Program's Name & Welcome Message Display.
private JPanel statusBar = new JPanel ();
//Labels for Displaying Program's Name & saying Welcome to Current User on StatusBar.
private JLabel welcome;
private JLabel author;
//Making the LookAndFeel Menu.
private String strings[] = {"1. Metal", "2. Motif", "3. Windows"};
private UIManager.LookAndFeelInfo looks[] = UIManager.getInstalledLookAndFeels ();
private ButtonGroup group = new ButtonGroup ();
private JRadioButtonMenuItem radio[] = new JRadioButtonMenuItem[strings.length];
//Getting the Current System Date.
private java.util.Date currDate = new java.util.Date ();
private SimpleDateFormat sdf = new SimpleDateFormat ("dd MMMM yyyy", Locale.getDefault());
private String d = sdf.format (currDate);
//Following all Variables are use in BankSystem's IO's.
//Variable use in Reading the BankSystem Records File & Store it in an Array.
private int count = 0;
private int rows = 0;
private int total = 0;
//String Type Array use to Load Records From File.
private String records[][] = new String [500][6];
//Variable for Reading the BankSystem Records File.
private FileInputStream fis;
private DataInputStream dis;
//Constructor of The Bank Program to Iniatilize all Variables of Program.
public BankSystem () {
//Setting Program's Title.
super ("BankSystem [Pvt] Limited.");
UIManager.addPropertyChangeListener (new UISwitchListener ((JComponent)getRootPane()));
//Creating the MenuBar.
bar = new JMenuBar ();
//Setting the Main Window of Program.
setIconImage (getToolkit().getImage ("Images/Bank.gif"));
setSize (700, 550);
setJMenuBar (bar);
//Closing Code of Main Window.
addWindowListener (new WindowAdapter () {
public void windowClosing (WindowEvent we) {
quitApp ();
}
}
);
//Setting the Location of Application on Screen.
setLocation((Toolkit.getDefaultToolkit().getScreenSize().width - getWidth()) / 2,
(Toolkit.getDefaultToolkit().getScreenSize().height - getHeight()) / 2);
//Creating the MenuBar Items.
mnuFile = new JMenu ("File");
mnuFile.setMnemonic ((int)'F');
mnuEdit = new JMenu ("Edit");
mnuEdit.setMnemonic ((int)'E');
mnuView = new JMenu ("View");
mnuView.setMnemonic ((int)'V');
mnuOpt = new JMenu ("Options");
mnuOpt.setMnemonic ((int)'O');
mnuWin = new JMenu ("Window");
mnuWin.setMnemonic ((int)'W');
mnuHelp = new JMenu ("Help");
mnuHelp.setMnemonic ((int)'H');
//Creating the MenuItems of Program.
//MenuItems for FileMenu.
addNew = new JMenuItem ("Open New Account", new ImageIcon ("Images/Open.gif"));
addNew.setAccelerator (KeyStroke.getKeyStroke(KeyEvent.VK_N, Event.CTRL_MASK));
addNew.setMnemonic ((int)'N');
addNew.addActionListener (this);
printRec = new JMenuItem ("Print Customer Balance", new ImageIcon ("Images/New.gif"));
printRec.setAccelerator (KeyStroke.getKeyStroke(KeyEvent.VK_R, Event.CTRL_MASK));
printRec.setMnemonic ((int)'R');
printRec.addActionListener (this);
end = new JMenuItem ("Quit BankSystem ?", new ImageIcon ("Images/export.gif"));
end.setAccelerator (KeyStroke.getKeyStroke(KeyEvent.VK_Q, Event.CTRL_MASK));
end.setMnemonic ((int)'Q');
end.addActionListener (this);
//MenuItems for EditMenu.
deposit = new JMenuItem ("Deposit Money");
deposit.setAccelerator (KeyStroke.getKeyStroke(KeyEvent.VK_T, Event.CTRL_MASK));
deposit.setMnemonic ((int)'T');
deposit.addActionListener (this);
withdraw = new JMenuItem ("Withdraw Money");
withdraw.setAccelerator (KeyStroke.getKeyStroke(KeyEvent.VK_W, Event.CTRL_MASK));
withdraw.setMnemonic ((int)'W');
withdraw.addActionListener (this);
delRec = new JMenuItem ("Delete Customer", new ImageIcon ("Images/Delete.gif"));
delRec.setAccelerator (KeyStroke.getKeyStroke(KeyEvent.VK_D, Event.CTRL_MASK));
delRec.setMnemonic ((int)'D');
delRec.addActionListener (this);
search = new JMenuItem ("Search By No.", new ImageIcon ("Images/find.gif"));
search.setAccelerator (KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.CTRL_MASK));
search.setMnemonic ((int)'S');
search.addActionListener (this);
searchName = new JMenuItem ("Search By Name");
searchName.setAccelerator (KeyStroke.getKeyStroke(KeyEvent.VK_M, Event.CTRL_MASK));
searchName.setMnemonic ((int)'M');
searchName.addActionListener (this);
//MenuItems for ViewMenu.
oneByOne = new JMenuItem ("View One By One");
oneByOne.setAccelerator (KeyStroke.getKeyStroke(KeyEvent.VK_O, Event.CTRL_MASK));
oneByOne.setMnemonic ((int)'O');
oneByOne.addActionListener (this);
allCustomer = new JMenuItem ("View All Customer", new ImageIcon ("Images/refresh.gif"));
allCustomer.setAccelerator (KeyStroke.getKeyStroke(KeyEvent.VK_A, Event.CTRL_MASK));
allCustomer.setMnemonic ((int)'A');
allCustomer.addActionListener (this);
//MenuItems for OptionMenu.
change = new JMenuItem ("Change Background Color");
change.setAccelerator (KeyStroke.getKeyStroke(KeyEvent.VK_B, Event.CTRL_MASK));
change.setMnemonic ((int)'B');
change.addActionListener (this);
//Menu For Changing the Program's Layout.
style = new JMenu ("Change Layout Style");
style.setMnemonic ((int)'L');
for( int i = 0; i < radio.length ; i++ ) { //Creating the subMenus of Style Menu.
radio[i] = new JRadioButtonMenuItem (strings[i]); //Build an Array of Layouts to Apply.
radio[i].addItemListener (this); //Setting their Actions.
group.add (radio[i]); //Making them Grouped.
style.add (radio[i]); //Adding to Style MenuOption.
}
//SubMenu of Theme For Applying different Themes to Program By Building an Array of Themes to Apply.
MetalTheme[] themes = { new DefaultMetalTheme(), new GreenTheme(), new AquaTheme(),
new SandTheme(), new SolidTheme(), new MilkyTheme(), new GrayTheme() };
theme = new MetalThemeMenu ("Apply Theme", themes); //Putting the Themes in ThemeMenu.
theme.setMnemonic ((int)'M');
//MenuItems for WindowMenu.
close = new JMenuItem ("Close Active Window");
close.setMnemonic ((int)'C');
close.addActionListener (this);
closeAll = new JMenuItem ("Close All Windows...");
closeAll.setMnemonic ((int)'A');
closeAll.addActionListener (this);
//MenuItems for HelpMenu.
content = new JMenuItem ("Help Contents", new ImageIcon ("Images/paste.gif"));
content.setAccelerator (KeyStroke.getKeyStroke(KeyEvent.VK_H, Event.CTRL_MASK));
content.setMnemonic ((int)'H');
content.addActionListener (this);
keyHelp = new JMenuItem ("Help on Shortcuts...");
keyHelp.setAccelerator (KeyStroke.getKeyStroke(KeyEvent.VK_K, Event.CTRL_MASK));
keyHelp.setMnemonic ((int)'K');
keyHelp.addActionListener (this);
about = new JMenuItem ("About BankSystem", new ImageIcon ("Images/Save.gif"));
about.setAccelerator (KeyStroke.getKeyStroke(KeyEvent.VK_C, Event.CTRL_MASK));
about.setMnemonic ((int)'C');
about.addActionListener (this);
//Adding MenuItems to Menu.
//File Menu Items.
mnuFile.add (addNew);
mnuFile.addSeparator ();
mnuFile.add (printRec);
mnuFile.addSeparator ();
mnuFile.add (end);
//Edit Menu Items.
mnuEdit.add (deposit);
mnuEdit.add (withdraw);
mnuEdit.addSeparator ();
mnuEdit.add (delRec);
mnuEdit.addSeparator ();
mnuEdit.add (search);
mnuEdit.add (searchName);
//View Menu Items.
mnuView.add (oneByOne);
mnuView.addSeparator ();
mnuView.add (allCustomer);
//Options Menu Items.
mnuOpt.add (change);
mnuOpt.addSeparator ();
mnuOpt.add (style);
mnuOpt.addSeparator ();
mnuOpt.add (theme);
//Window Menu Items.
mnuWin.add (close);
mnuWin.add (closeAll);
//Help Menu Items.
mnuHelp.add (content);
mnuHelp.addSeparator ();
mnuHelp.add (keyHelp);
mnuHelp.addSeparator ();
mnuHelp.add (about);
//Adding Menues to Bar.
bar.add (mnuFile);
bar.add (mnuEdit);
bar.add (mnuView);
bar.add (mnuOpt);
bar.add (mnuWin);
bar.add (mnuHelp);
//MenuItems for PopupMenu.
open = new JMenuItem ("Open New Account", new ImageIcon ("Images/Open.gif"));
open.addActionListener (this);
report = new JMenuItem ("Print BankSystem Report", new ImageIcon ("Images/New.gif"));
report.addActionListener (this);
dep = new JMenuItem ("Deposit Money");
dep.addActionListener (this);
with = new JMenuItem ("Withdraw Money");
with.addActionListener (this);
del = new JMenuItem ("Delete Customer", new ImageIcon ("Images/Delete.gif"));
del.addActionListener (this);
find = new JMenuItem ("Search Customer", new ImageIcon ("Images/find.gif"));
find.addActionListener (this);
all = new JMenuItem ("View All Customer", new ImageIcon ("Images/refresh.gif"));
all.addActionListener (this);
//Adding Menues to PopupMenu.
popMenu.add (open);
popMenu.add (report);
popMenu.add (dep);
popMenu.add (with);
popMenu.add (del);
popMenu.add (find);
popMenu.add (all);
//Following Procedure display the PopupMenu of Program.
addMouseListener (new MouseAdapter () {
public void mousePressed (MouseEvent me) { checkMouseTrigger (me); }
public void mouseReleased (MouseEvent me) { checkMouseTrigger (me); }
private void checkMouseTrigger (MouseEvent me) {
if (me.isPopupTrigger ())
popMenu.show (me.getComponent (), me.getX (), me.getY ());
}
}
);
//Creating the ToolBar's Buttons of Program.
btnNew = new JButton (new ImageIcon ("Images/NotePad.gif"));
btnNew.setToolTipText ("Create New Account");
btnNew.addActionListener (this);
btnDep = new JButton (new ImageIcon ("Images/ImationDisk.gif"));
btnDep.setToolTipText ("Deposit Money");
btnDep.addActionListener (this);
btnWith = new JButton (new ImageIcon ("Images/SuperDisk.gif"));
btnWith.setToolTipText ("Withdraw Money");
btnWith.addActionListener (this);
btnRec = new JButton (new ImageIcon ("Images/Paproll.gif"));
btnRec.setToolTipText ("Print Customer Balance");
btnRec.addActionListener (this);
btnDel = new JButton (new ImageIcon ("Images/Toaster.gif"));
btnDel.setToolTipText ("Delete Customer");
btnDel.addActionListener (this);
btnSrch = new JButton (new ImageIcon ("Images/Search.gif"));
btnSrch.setToolTipText ("Search Customer");
btnSrch.addActionListener (this);
btnHelp = new JButton (new ImageIcon ("Images/Help.gif"));
btnHelp.setToolTipText ("Help on Bank System");
btnHelp.addActionListener (this);
btnKey = new JButton (new ImageIcon ("Images/Keys.gif"));
btnKey.setToolTipText ("Shortcut Keys of BankSystem");
btnKey.addActionListener (this);
//Creating the ToolBar of Program.
toolBar = new JToolBar ();
toolBar.add (btnNew);
toolBar.addSeparator ();
toolBar.add (btnDep);
toolBar.add (btnWith);
toolBar.addSeparator ();
toolBar.add (btnRec);
toolBar.addSeparator ();
toolBar.add (btnDel);
toolBar.addSeparator ();
toolBar.add (btnSrch);
toolBar.addSeparator ();
toolBar.add (btnHelp);
toolBar.add (btnKey);
//Creating the StatusBar of Program.
author = new JLabel (" " + "BankSystem [Pvt] Limited.", Label.LEFT);
author.setForeground (Color.black);
author.setToolTipText ("Program's Title");
welcome = new JLabel ("Welcome Today is " + d + " ", JLabel.RIGHT);
welcome.setForeground (Color.black);
welcome.setToolTipText ("Welcoming the User & System Current Date");
statusBar.setLayout (new BorderLayout());
statusBar.add (author, BorderLayout.WEST);
statusBar.add (welcome, BorderLayout.EAST);
//For Making the Dragging Speed of Internal Frames Faster.
desktop.putClientProperty ("JDesktopPane.dragMode", "outline");
//Setting the Contents of Programs.
getContentPane().add (toolBar, BorderLayout.NORTH);
getContentPane().add (desktop, BorderLayout.CENTER);
getContentPane().add (statusBar, BorderLayout.SOUTH);
//Showing The Main Form of Application.
setVisible (true);
}
//Function For Performing different Actions By Menus of Program.
public void actionPerformed (ActionEvent ae) {
Object obj = ae.getSource();
if (obj == addNew || obj == open || obj == btnNew) {
boolean b = openChildWindow ("Create New Account");
if (b == false) {
NewAccount newAcc = new NewAccount ();
desktop.add (newAcc);
newAcc.show ();
}
}
else if (obj == printRec || obj == btnRec || obj == report) {
getAccountNo ();
}
else if (obj == end) {
quitApp ();
}
else if (obj == deposit || obj == dep || obj == btnDep) {
boolean b = openChildWindow ("Deposit Money");
if (b == false) {
DepositMoney depMon = new DepositMoney ();
desktop.add (depMon);
depMon.show ();
}
}
else if (obj == withdraw || obj == with || obj == btnWith) {
boolean b = openChildWindow ("Withdraw Money");
if (b == false) {
WithdrawMoney withMon = new WithdrawMoney ();
desktop.add (withMon);
withMon.show ();
}
}
else if (obj == delRec || obj == del || obj == btnDel) {
boolean b = openChildWindow ("Delete Account Holder");
if (b == false) {
DeleteCustomer delCus = new DeleteCustomer ();
desktop.add (delCus);
delCus.show ();
}
}
else if (obj == search || obj == find || obj == btnSrch) {
boolean b = openChildWindow ("Search Customer [By No.]");
if (b == false) {
FindAccount fndAcc = new FindAccount ();
desktop.add (fndAcc);
fndAcc.show ();
}
}
else if (obj == searchName) {
boolean b = openChildWindow ("Search Customer [By Name]");
if (b == false) {
FindName fndNm = new FindName ();
desktop.add (fndNm);
fndNm.show ();
}
}
else if (obj == oneByOne) {
boolean b = openChildWindow ("View Account Holders");
if (b == false) {
ViewOne vwOne = new ViewOne ();
desktop.add (vwOne);
vwOne.show ();
}
}
else if (obj == allCustomer || obj == all) {
boolean b = openChildWindow ("View All Account Holders");
if (b == false) {
ViewCustomer viewCus = new ViewCustomer ();
desktop.add (viewCus);
viewCus.show ();
}
}
else if (obj == change) {
Color cl = new Color (153, 153, 204);
cl = JColorChooser.showDialog (this, "Choose Background Color", cl);
if (cl == null) { }
else {
desktop.setBackground (cl);
desktop.repaint ();
}
}
else if (obj == close) {
try {
desktop.getSelectedFrame().setClosed(true);
}
catch (Exception CloseExc) { }
}
else if (obj == closeAll) {
JInternalFrame Frames[] = desktop.getAllFrames (); //Getting all Open Frames.
for(int getFrameLoop = 0; getFrameLoop < Frames.length; getFrameLoop++) {
try {
Frames[getFrameLoop].setClosed (true); //Close the frame.
}
catch (Exception CloseExc) { } //if we can't close it then we have a problem.
}
}
else if (obj == content || obj == btnHelp) {
boolean b = openChildWindow ("BankSystem Help");
if (b == false) {
BankHelp hlpBank = new BankHelp ("BankSystem Help", "Help/Bank.htm");
desktop.add (hlpBank);
hlpBank.show ();
}
}
else if (obj == keyHelp || obj == btnKey) {
boolean b = openChildWindow ("BankSystem Keys");
if (b == false) {
BankHelp hlpKey = new BankHelp ("BankSystem Keys", "Help/Keys.htm");
desktop.add (hlpKey);
hlpKey.show ();
}
}
else if (obj == about) {
String msg = "BankSystem [Pvt] Limited.\n\n" + "Created & Designed By:\n" +
"Sattwik Manna\n\n" + "E-mail me:\n sattwikmanna6359@gmail.com";
JOptionPane.showMessageDialog (this, msg, "About BankSystem", JOptionPane.PLAIN_MESSAGE);
}
}
//Function Perform By LookAndFeel Menu.
public void itemStateChanged (ItemEvent e) {
for( int i = 0; i < radio.length; i++ )
if(radio[i].isSelected()) {
changeLookAndFeel (i);
}
}
//Function For Closing the Program.
private void quitApp () {
try {
//Show a Confirmation Dialog.
int reply = JOptionPane.showConfirmDialog (this,
"Are you really want to exit\nFrom BankSystem?",
"BankSystem - Exit", JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE);
//Check the User Selection.
if (reply == JOptionPane.YES_OPTION) {
setVisible (false); //Hide the Frame.
dispose(); //Free the System Resources.
System.out.println ("Thanks for Using BankSystem\nAuthor - Sattwik Manna");
System.exit (0); //Close the Application.
}
else if (reply == JOptionPane.NO_OPTION) {
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
}
}
catch (Exception e) {}
}
//Function for Changing the Program's Look.
public void changeLookAndFeel (int val) {
try {
UIManager.setLookAndFeel (looks[val].getClassName());
SwingUtilities.updateComponentTreeUI (this);
}
catch (Exception e) { }
}
//Loop Through All the Opened JInternalFrame to Perform the Task.
private boolean openChildWindow (String title) {
JInternalFrame[] childs = desktop.getAllFrames ();
for (int i = 0; i < childs.length; i++) {
if (childs[i].getTitle().equalsIgnoreCase (title)) {
childs[i].show ();
return true;
}
}
return false;
}
//Following Functions use for Printing Records & Report of BankSystem.
void getAccountNo () {
String printing;
rows = 0;
boolean b = populateArray ();
if (b == false) { }
else {
try {
printing = JOptionPane.showInputDialog (this, "Enter Account No. to Print Customer Balance.\n" +
"(Tip: Account No. Contains only Digits)", "BankSystem - PrintRecord", JOptionPane.PLAIN_MESSAGE);
if (printing == null) { }
if (printing.equals ("")) {
JOptionPane.showMessageDialog (this, "Provide Account No. to Print.",
"BankSystem - EmptyField", JOptionPane.PLAIN_MESSAGE);
getAccountNo ();
}
else {
findRec (printing);
}
}
catch (Exception e) { }
}
}
//Function use to load all Records from File when Application Execute.
boolean populateArray () {
boolean b = false;
try {
fis = new FileInputStream ("Bank.dat");
dis = new DataInputStream (fis);
//Loop to Populate the Array.
while (true) {
for (int i = 0; i < 6; i++) {
records[rows][i] = dis.readUTF ();
}
rows++;
}
}
catch (Exception ex) {
total = rows;
if (total == 0) {
JOptionPane.showMessageDialog (null, "Records File is Empty.\nEnter Records First to Display.",
"BankSystem - EmptyFile", JOptionPane.PLAIN_MESSAGE);
b = false;
}
else {
b = true;
try {
dis.close();
fis.close();
}
catch (Exception exp) { }
}
}
return b;
}
//Function use to Find Record by Matching the Contents of Records Array with InputBox.
void findRec (String rec) {
boolean found = false;
for (int x = 0; x < total; x++) {
if (records[x][0].equals (rec)) {
found = true;
printRecord (makeRecordPrint (x));
break;
}
}
if (found == false) {
JOptionPane.showMessageDialog (this, "Account No. " + rec + " doesn't Exist.",
"BankSystem - WrongNo", JOptionPane.PLAIN_MESSAGE);
getAccountNo ();
}
}
//Function use to make Current Record ready for Print.
String makeRecordPrint (int rec) {
String data;
String data0 = " BankSystem [Pvt] Limited. \n"; //Page Title.
String data1 = " Customer Balance Report. \n\n"; //Page Header.
String data2 = " Account No.: " + records[rec][0] + "\n";
String data3 = " Customer Name: " + records[rec][1] + "\n";
String data4 = " Last Transaction: " + records[rec][2] + ", " + records[rec][3] + ", " + records[rec][4] + "\n";
String data5 = " Current Balance: " + records[rec][5] + "\n\n";
String data6 = " Copyright � 2021 Sattwik Manna.\n"; //Page Footer.
String sep0 = " -----------------------------------------------------------\n";
String sep1 = " -----------------------------------------------------------\n";
String sep2 = " -----------------------------------------------------------\n";
String sep3 = " -----------------------------------------------------------\n";
String sep4 = " -----------------------------------------------------------\n\n";
data = data0 + sep0 + data1 + data2 + sep1 + data3 + sep2 + data4 + sep3 + data5 + sep4 + data6;
return data;
}
//Function use to Print the Current Record.
void printRecord (String rec) {
StringReader sr = new StringReader (rec);
LineNumberReader lnr = new LineNumberReader (sr);
Font typeface = new Font ("Times New Roman", Font.PLAIN, 12);
Properties p = new Properties ();
PrintJob pJob = getToolkit().getPrintJob (this, "Print Customer Balance Report", p);
if (pJob != null) {
Graphics gr = pJob.getGraphics ();
if (gr != null) {
FontMetrics fm = gr.getFontMetrics (typeface);
int margin = 20;
int pageHeight = pJob.getPageDimension().height - margin;
int fontHeight = fm.getHeight();
int fontDescent = fm.getDescent();
int curHeight = margin;
String nextLine;
gr.setFont (typeface);
try {
do {
nextLine = lnr.readLine ();
if (nextLine != null) {
if ((curHeight + fontHeight) > pageHeight) { //New Page.
gr.dispose();
gr = pJob.getGraphics ();
curHeight = margin;
}
curHeight += fontHeight;
if (gr != null) {
gr.setFont (typeface);
gr.drawString (nextLine, margin, curHeight - fontDescent);
}
}
}
while (nextLine != null);
}
catch (EOFException eof) { }
catch (Throwable t) { }
}
gr.dispose();
}
if (pJob != null)
pJob.end ();
}
}