-
Notifications
You must be signed in to change notification settings - Fork 0
/
ViewCustomer.java
112 lines (89 loc) · 2.85 KB
/
ViewCustomer.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
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.table.DefaultTableModel;
public class ViewCustomer extends JInternalFrame {
private JPanel jpShow = new JPanel ();
private DefaultTableModel dtmCustomer;
private JTable tbCustomer;
private JScrollPane jspTable;
private int row = 0;
private int total = 0;
//String Type Array use to Load Records into File.
private String rowData[][];
private FileInputStream fis;
private DataInputStream dis;
ViewCustomer () {
//super(Title, Resizable, Closable, Maximizable, Iconifiable)
super ("View All Account Holders", false, true, false, true);
setSize (475, 280);
jpShow.setLayout (null);
populateArray ();
tbCustomer = makeTable ();
jspTable = new JScrollPane (tbCustomer);
jspTable.setBounds (20, 20, 425, 200);
//Adding the Table to Panel.
jpShow.add (jspTable);
//Adding Panel to Window.
getContentPane().add (jpShow);
//In the End Showing the New Account Window.
setVisible (true);
}
//Function use to load all Records from File when Window Open.
void populateArray () {
//String Type Array use to Load Records into File.
String rows[][] = new String [500][6];
try {
fis = new FileInputStream ("Bank.dat");
dis = new DataInputStream (fis);
//Loop to Populate the Array.
while (true) {
for (int i = 0; i < 6; i++) {
rows[row][i] = dis.readUTF ();
}
row++;
}
}
catch (Exception ex) {
total = row;
rowData = new String [total][4];
if (total == 0) {
JOptionPane.showMessageDialog (null, "Records File is Empty.\nEnter Records to Display.",
"BankSystem - EmptyFile", JOptionPane.PLAIN_MESSAGE);
}
else {
for (int i = 0; i < total; i++) {
rowData[i][0] = rows[i][0];
rowData[i][1] = rows[i][1];
rowData[i][2] = rows[i][2] + ", " + rows[i][3] + ", " + rows[i][4];
rowData[i][3] = rows[i][5];
}
try {
dis.close();
fis.close();
}
catch (Exception exp) { }
}
}
}
//Function to Create the Table and Add Data to Show.
private JTable makeTable () {
//String Type Array use to Give Table Column Names.
String cols[] = {"Account No.", "Customer Name", "Opening Date", "Bank Balance"};
dtmCustomer = new DefaultTableModel (rowData, cols);
tbCustomer = new JTable (dtmCustomer) {
public boolean isCellEditable (int iRow, int iCol) {
return false; //Disable All Columns of Table.
}
};
//Sizing the Columns of Table.
(tbCustomer.getColumnModel().getColumn(0)).setPreferredWidth (180);
(tbCustomer.getColumnModel().getColumn(1)).setPreferredWidth (275);
(tbCustomer.getColumnModel().getColumn(2)).setPreferredWidth (275);
(tbCustomer.getColumnModel().getColumn(3)).setPreferredWidth (200);
tbCustomer.setRowHeight (20);
tbCustomer.setSelectionMode (ListSelectionModel.SINGLE_SELECTION);
return tbCustomer;
}
}