-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInterface.java
281 lines (233 loc) · 8.08 KB
/
Interface.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
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.io.File;
import java.awt.event.ActionEvent;
import java.awt.SystemColor;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.JTable;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.table.DefaultTableModel;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.FlowLayout;
import javax.swing.BoxLayout;
import java.awt.Component;
import java.awt.Insets;
public class Interface extends JFrame{
/**
*
*/
private static final long serialVersionUID = 1L;
public JFrame frame;
private JTextArea outputArea;
private JTable table;
JTextArea searchText = new JTextArea();
AccountRecordSerializable currentRecordSelection = new AccountRecordSerializable();
AccountRecordSerializable searched = new AccountRecordSerializable();
ClientAccess ca = new ClientAccess();
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Interface window = new Interface();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public Interface() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 720, 480);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JMenuBar menuBar = new JMenuBar();
frame.setJMenuBar(menuBar);
JMenu mnFile = new JMenu("File");
menuBar.add(mnFile);
JMenuItem mntmLoadFile = new JMenuItem("Load File");
mntmLoadFile.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
showInfo();
}
});
mnFile.add(mntmLoadFile);
JMenuItem mntmExit = new JMenuItem("Exit");
mnFile.add(mntmExit);
frame.getContentPane().setLayout(new BorderLayout(0, 0));
JPanel search = new JPanel();
search.setAlignmentX(Component.RIGHT_ALIGNMENT);
search.setAlignmentY(Component.BOTTOM_ALIGNMENT);
frame.getContentPane().add(search, BorderLayout.SOUTH);
table = new JTable();
table.setModel(new DefaultTableModel(
new Object[][] {
{null, null, null, null},
},
new String[] {
"Account Number", "First Name", "Last Name", "Account Balance"
}
) {
Class[] columnTypes = new Class[] {
Integer.class, String.class, String.class, Double.class
};
public Class getColumnClass(int columnIndex) {
return columnTypes[columnIndex];
}
boolean[] columnEditables = new boolean[] {
false, false, false, false
};
public boolean isCellEditable(int row, int column) {
return columnEditables[column];
}
});
table.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
@Override
public void valueChanged(ListSelectionEvent e) {
currentRecordSelection = ca.getRecord(Integer.parseInt(table.getValueAt(table.getSelectedRow(), 0).toString()));
//System.out.println(table.getValueAt(table.getSelectedRow(), 0).toString());
}
});
search.setLayout(new BorderLayout(0, 0));
//search.add(scrollPane_1,BorderLayout.SOUTH);
search.add(table);
JLabel lblSearchResult = new JLabel("Search result:");
search.add(lblSearchResult, BorderLayout.WEST);
// table.getModel().setValueAt(timePlay, 0, 1);
JPanel panel = new JPanel();
frame.getContentPane().add(panel, BorderLayout.WEST);
panel.setLayout(new GridLayout(0, 1, 0, 0));
JButton addButton = new JButton("Add Record");
addButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
AddRecord newRecord = new AddRecord();
newRecord.frame.setVisible(true);
}
});
panel.add(addButton);
JButton removeButton = new JButton("Remove Record");
removeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
panel.add(removeButton);
JButton editButton = new JButton("Edit Record");
editButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
panel.add(editButton);
searchText.setBackground(SystemColor.control);
searchText.setText("Enter Account Number");
JButton searchButton = new JButton("Search ");
searchButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try{
int toSearch = Integer.parseInt(searchText.getText());
}
catch(NumberFormatException nf){
JOptionPane.showMessageDialog(frame, "Invalid Search. Enter a number.","Invalid Name",JOptionPane.ERROR_MESSAGE);
}
searched = ca.getRecord(Integer.parseInt(searchText.getText()));
System.out.println(ca.getRecord(Integer.parseInt(searchText.getText())).getFirstName());
outputArea.setText(ca.getRecord(Integer.parseInt(searchText.getText())).getFirstName());
/*table.getModel().setValueAt(searched.getAccount(), 0, 0);
table.getModel().setValueAt(searched.getFirstName(), 0, 1);
table.getModel().setValueAt(searched.getLastName(), 0, 2);
table.getModel().setValueAt(searched.getBalance(), 0, 3);
*/
}
});
panel.add(searchButton);
panel.add(searchText);
outputArea = new JTextArea();
frame.getContentPane().add(outputArea);
JScrollPane scrollPane_1 = new JScrollPane();
JPanel panel_1 = new JPanel();
frame.getContentPane().add(panel_1, BorderLayout.NORTH);
panel_1.setLayout(new GridLayout(2, 4, 0, 0));
JLabel DisplayAN = new JLabel("Account Number");
DisplayAN.setHorizontalAlignment(SwingConstants.CENTER);
panel_1.add(DisplayAN);
JLabel DisplayFN = new JLabel("First Name");
DisplayFN.setHorizontalAlignment(SwingConstants.CENTER);
panel_1.add(DisplayFN);
JLabel DisplayLN = new JLabel("Last Name");
DisplayLN.setHorizontalAlignment(SwingConstants.CENTER);
panel_1.add(DisplayLN);
JLabel DisplayAB = new JLabel("Account Balance");
DisplayAB.setHorizontalAlignment(SwingConstants.CENTER);
panel_1.add(DisplayAB);
JTextArea textAreaAN = new JTextArea();
textAreaAN.setBackground(SystemColor.controlHighlight);
textAreaAN.setEditable(false);
panel_1.add(textAreaAN);
JTextArea textAreaFN = new JTextArea();
textAreaFN.setEditable(false);
textAreaFN.setBackground(SystemColor.scrollbar);
panel_1.add(textAreaFN);
JTextArea textAreaLN = new JTextArea();
textAreaLN.setEditable(false);
textAreaLN.setBackground(SystemColor.controlHighlight);
panel_1.add(textAreaLN);
JTextArea textAreaAB = new JTextArea();
textAreaAB.setEditable(false);
textAreaAB.setBackground(SystemColor.scrollbar);
panel_1.add(textAreaAB);
}
private File getFile()
{
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
int result = fileChooser.showOpenDialog(this);
if(result == JFileChooser.CANCEL_OPTION){
System.exit(1);
}
File fileName = fileChooser.getSelectedFile();
if((fileName==null) || (fileName.getName().equals("")))
{
JOptionPane.showMessageDialog(this, "Invalid Name","Invalid Name",JOptionPane.ERROR_MESSAGE);
System.exit(1);
}
return fileName;
}
public void showInfo()
{
File name = getFile();
if(name.exists())
{
outputArea.setText("Made it");
}
else
{
JOptionPane.showMessageDialog(this, name + " does not exist.", "ERROR", JOptionPane.ERROR_MESSAGE);
}
}
}