KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > ebank > appclient > BankAdmin


1 /*
2  * Copyright (c) 2004 Sun Microsystems, Inc. All rights reserved. U.S.
3  * Government Rights - Commercial software. Government users are subject
4  * to the Sun Microsystems, Inc. standard license agreement and
5  * applicable provisions of the FAR and its supplements. Use is subject
6  * to license terms.
7  *
8  * This distribution may include materials developed by third parties.
9  * Sun, Sun Microsystems, the Sun logo, Java and J2EE are trademarks
10  * or registered trademarks of Sun Microsystems, Inc. in the U.S. and
11  * other countries.
12  *
13  * Copyright (c) 2004 Sun Microsystems, Inc. Tous droits reserves.
14  *
15  * Droits du gouvernement americain, utilisateurs gouvernementaux - logiciel
16  * commercial. Les utilisateurs gouvernementaux sont soumis au contrat de
17  * licence standard de Sun Microsystems, Inc., ainsi qu'aux dispositions
18  * en vigueur de la FAR (Federal Acquisition Regulations) et des
19  * supplements a celles-ci. Distribue par des licences qui en
20  * restreignent l'utilisation.
21  *
22  * Cette distribution peut comprendre des composants developpes par des
23  * tierces parties. Sun, Sun Microsystems, le logo Sun, Java et J2EE
24  * sont des marques de fabrique ou des marques deposees de Sun
25  * Microsystems, Inc. aux Etats-Unis et dans d'autres pays.
26  */

27
28
29 package com.sun.ebank.appclient;
30
31 import java.util.Locale JavaDoc;
32 import java.util.ResourceBundle JavaDoc;
33 import java.text.NumberFormat JavaDoc;
34 import java.text.DateFormat JavaDoc;
35 import java.io.File JavaDoc;
36 import java.io.RandomAccessFile JavaDoc;
37 import java.io.FileNotFoundException JavaDoc;
38 import java.io.IOException JavaDoc;
39 import java.util.ArrayList JavaDoc;
40 import java.util.Date JavaDoc;
41 import java.math.BigDecimal JavaDoc;
42 import java.awt.GridLayout JavaDoc;
43 import java.awt.Color JavaDoc;
44 import java.awt.event.WindowAdapter JavaDoc;
45 import java.awt.event.WindowListener JavaDoc;
46 import java.awt.event.WindowEvent JavaDoc;
47 import java.awt.event.KeyEvent JavaDoc;
48 import javax.swing.*;
49
50
51 public class BankAdmin extends JFrame {
52     //Protected instance variables
53
protected static BankAdmin frame;
54     protected static EventHandle ehandle;
55
56     //Internationalization
57
private static Locale JavaDoc currentLocale = null;
58     protected static ResourceBundle JavaDoc messages = null;
59     protected String JavaDoc desc;
60     protected JButton OK;
61     protected JButton cancel;
62     protected JPanel p1;
63     protected JPanel p2;
64     protected JLabel fnamelab;
65     protected JLabel lnamelab;
66     protected JLabel milab;
67     protected JLabel streetlab;
68     protected JLabel citylab;
69     protected JLabel statelab;
70     protected JLabel ziplab;
71     protected JLabel phonelab;
72     protected JLabel emaillab;
73     protected JLabel spacerlab1;
74     protected JLabel spacerlab2;
75     protected JLabel messlab;
76     protected JLabel messlab2;
77     protected JLabel messlab3;
78     protected JLabel messlab4;
79     protected JLabel messlab5;
80     protected JLabel messlab6;
81     protected JLabel descriplab;
82     protected JLabel typelab;
83     protected JLabel balab;
84     protected JLabel creditlab;
85     protected JLabel begbalab;
86     protected JLabel customerlab;
87     protected JLabel timelab;
88     protected JMenuBar mb;
89     protected JMenu custmenu;
90     protected JMenu actmenu;
91     protected JMenuItem createcust;
92     protected JMenuItem viewcust;
93     protected JMenuItem updatecust;
94     protected JMenuItem createact;
95     protected JMenuItem viewact;
96     protected JMenuItem addcust;
97     protected JMenuItem remact;
98     protected JMenuItem srchcust;
99     protected JRadioButton checkingact;
100     protected JRadioButton savingsact;
101     protected JRadioButton creditact;
102     protected JRadioButton mnymktact;
103     protected ButtonGroup group;
104     protected JPanel radioPanel;
105
106     //Editable variables
107
protected JTextField fname;
108
109     //Editable variables
110
protected JTextField lname;
111
112     //Editable variables
113
protected JTextField mi;
114
115     //Editable variables
116
protected JTextField street;
117
118     //Editable variables
119
protected JTextField city;
120
121     //Editable variables
122
protected JTextField state;
123
124     //Editable variables
125
protected JTextField account;
126
127     //Editable variables
128
protected JTextField customer;
129
130     //Editable variables
131
protected JTextField zip;
132
133     //Editable variables
134
protected JTextField phone;
135
136     //Editable variables
137
protected JTextField e;
138
139     //Editable variables
140
protected JTextField descrip;
141
142     //Editable variables
143
protected JTextField type;
144
145     //Editable variables
146
protected JTextField bal;
147
148     //Editable variables
149
protected JTextField credit;
150
151     //Editable variables
152
protected JTextField begbal;
153
154     //Editable variables
155
protected JTextField cust;
156
157     //Editable variables
158
protected JTextField time;
159
160     //Constructor
161
public BankAdmin(Locale JavaDoc currentLocale) {
162         //Internationalization setup
163
messages =
164             ResourceBundle.getBundle("appclient.AdminMessages", currentLocale);
165
166         //Create initial UI (Panel 1)
167
getContentPane()
168             .setLayout(new GridLayout JavaDoc(1, 2));
169         p1 = new JPanel();
170         p1.setLayout(new GridLayout JavaDoc(20, 1));
171         p2 = new JPanel();
172         p2.setLayout(new GridLayout JavaDoc(0, 2));
173         p1.setBackground(Color.white);
174         p2.setBackground(Color.gray);
175         getContentPane()
176             .add(p1);
177         getContentPane()
178             .add(p2);
179
180         //Build menu bar
181
mb = new JMenuBar();
182         setJMenuBar(mb);
183
184         //Build Customer menu
185
custmenu = new JMenu(messages.getString("CustAdmin"), true);
186         custmenu.setMnemonic(KeyEvent.VK_C);
187         mb.add(custmenu);
188         createcust = new JMenuItem(messages.getString("CreateCust"));
189         createcust.setMnemonic(KeyEvent.VK_U);
190         viewcust = new JMenuItem(messages.getString("ViewCust"));
191         viewcust.setMnemonic(KeyEvent.VK_V);
192         updatecust = new JMenuItem(messages.getString("UpdateCust"));
193         updatecust.setMnemonic(KeyEvent.VK_D);
194         srchcust = new JMenuItem(messages.getString("SearchCust"));
195         srchcust.setMnemonic(KeyEvent.VK_S);
196         custmenu.add(createcust);
197         custmenu.add(viewcust);
198         custmenu.add(updatecust);
199         custmenu.add(srchcust);
200
201         //Build Account Menu
202
actmenu = new JMenu(messages.getString("ActAdmin"), true);
203         actmenu.setMnemonic(KeyEvent.VK_A);
204         mb.add(actmenu);
205         createact = new JMenuItem(messages.getString("CreateAct"));
206         createact.setMnemonic(KeyEvent.VK_R);
207         addcust = new JMenuItem(messages.getString("AddCust"));
208         addcust.setMnemonic(KeyEvent.VK_T);
209         viewact = new JMenuItem(messages.getString("ViewAct"));
210         viewact.setMnemonic(KeyEvent.VK_I);
211         remact = new JMenuItem(messages.getString("RemAct"));
212         remact.setMnemonic(KeyEvent.VK_O);
213         actmenu.add(createact);
214         actmenu.add(addcust);
215         actmenu.add(viewact);
216         actmenu.add(remact);
217
218         //Create Panel 2 OK and Cancel buttons
219
//So EventHandle constructor can add as action listeners
220
OK = new JButton(messages.getString("OKButton"));
221         cancel = new JButton(messages.getString("CancelButton"));
222
223         //Create message labels
224
messlab = new JLabel();
225         messlab2 = new JLabel();
226         messlab3 = new JLabel();
227         messlab4 = new JLabel();
228         messlab5 = new JLabel();
229         messlab6 = new JLabel();
230
231         //Add components to panels
232
p1.add(new JLabel());
233         p1.add(new JLabel());
234         p1.add(new JLabel());
235         p1.add(new JLabel());
236         p1.add(new JLabel());
237         p1.add(new JLabel());
238         p1.add(new JLabel());
239         p1.add(new JLabel());
240         p1.add(new JLabel());
241         p1.add(new JLabel());
242         p1.add(new JLabel());
243         p1.add(new JLabel());
244         p1.add(new JLabel());
245
246         String JavaDoc wmess = messages.getString("WatchMess");
247         p1.add(new JLabel(wmess + " "));
248         p1.add(messlab);
249         p1.add(messlab2);
250         p1.add(messlab3);
251         p1.add(messlab4);
252         p1.add(messlab5);
253         p1.add(messlab6);
254
255         //Create spacer labels
256
spacerlab1 = new JLabel("_____________________________");
257         spacerlab2 = new JLabel("_____________________________");
258
259         //Add spacer labels to Panel 2 initial screen
260
p2.add(spacerlab1);
261         p2.add(spacerlab2);
262
263         //Create description text field
264
this.descrip = new JTextField();
265
266         //Add functionality to close window
267
addWindowListener(new WindowAdapter JavaDoc() {
268                 public void windowClosing(WindowEvent JavaDoc event) {
269                     System.exit(0);
270                 }
271             });
272     }
273
274     protected void clearMessages(int value) {
275         messlab.setText(null);
276         messlab2.setText(null);
277         messlab3.setText(null);
278         messlab4.setText(null);
279         messlab5.setText(null);
280     }
281
282     protected void clearMessages() {
283         messlab.setText(null);
284         messlab2.setText(null);
285         messlab3.setText(null);
286         messlab4.setText(null);
287         messlab5.setText(null);
288         messlab6.setText(null);
289     }
290
291     protected void resetPanelTwo() {
292         clearMessages(1);
293         p2.removeAll();
294         p2.validate();
295         p2.repaint();
296     }
297
298     protected void createPanelTwoActLabels() {
299         descriplab = new JLabel(messages.getString("ActDescrip"));
300         descriplab.setLabelFor(descrip);
301         typelab = new JLabel(messages.getString("Type"));
302         typelab.setLabelFor(type);
303         balab = new JLabel(messages.getString("Balance"));
304         balab.setLabelFor(bal);
305         creditlab = new JLabel(messages.getString("Credit"));
306         creditlab.setLabelFor(credit);
307         begbalab = new JLabel(messages.getString("BegBal"));
308         begbalab.setLabelFor(begbal);
309         customerlab = new JLabel(messages.getString("Customers"));
310         customerlab.setLabelFor(cust);
311         timelab = new JLabel(messages.getString("Time"));
312         timelab.setLabelFor(time);
313     }
314
315     protected void createPanelTwoCustLabels() {
316         fnamelab = new JLabel(messages.getString("FnameLab"));
317         fnamelab.setLabelFor(fname);
318         lnamelab = new JLabel(messages.getString("LnameLab"));
319         lnamelab.setLabelFor(lname);
320         milab = new JLabel(messages.getString("MiLab"));
321         milab.setLabelFor(mi);
322         streetlab = new JLabel(messages.getString("StreetLab"));
323         streetlab.setLabelFor(street);
324         citylab = new JLabel(messages.getString("CityLab"));
325         citylab.setLabelFor(city);
326         statelab = new JLabel(messages.getString("StateLab"));
327         statelab.setLabelFor(state);
328         ziplab = new JLabel(messages.getString("ZipLab"));
329         ziplab.setLabelFor(zip);
330         phonelab = new JLabel(messages.getString("PhoneLab"));
331         phonelab.setLabelFor(phone);
332         emaillab = new JLabel(messages.getString("EmailLab"));
333         emaillab.setLabelFor(e);
334     }
335
336     protected void setDescription(String JavaDoc text) {
337         this.desc = text;
338
339         if (text != null) {
340             this.descrip.setText(this.desc);
341         }
342     }
343
344     protected void addCustToActFields(String JavaDoc custID, String JavaDoc actID) {
345         p2.removeAll();
346
347         JLabel actnolab = new JLabel(messages.getString("ActNoLab"));
348         JLabel custnolab = new JLabel(messages.getString("CustNoLab"));
349
350         if (custID != null) {
351             customer = new JTextField(custID);
352         } else {
353             customer = new JTextField();
354         }
355
356         if (actID != null) {
357             account = new JTextField(actID);
358         } else {
359             account = new JTextField();
360         }
361
362         p2.add(actnolab);
363         p2.add(account);
364         p2.add(custnolab);
365         p2.add(customer);
366         p2.add(OK);
367         p2.add(cancel);
368         p2.validate();
369         p2.repaint();
370     }
371
372     protected void createCustFields(boolean readonly, String JavaDoc first,
373         String JavaDoc last, String JavaDoc mid, String JavaDoc str, String JavaDoc cty, String JavaDoc st, String JavaDoc zp,
374         String JavaDoc tel, String JavaDoc mail) {
375         p2.removeAll();
376         createPanelTwoCustLabels();
377         fname = new JTextField(first);
378         lname = new JTextField(last);
379         mi = new JTextField(mid);
380         street = new JTextField(str);
381         city = new JTextField(cty);
382         state = new JTextField(st);
383         zip = new JTextField(zp);
384         phone = new JTextField(tel);
385         e = new JTextField(mail);
386
387         if (readonly == true) {
388             fname.setEditable(false);
389             lname.setEditable(false);
390             mi.setEditable(false);
391             street.setEditable(false);
392             city.setEditable(false);
393             state.setEditable(false);
394             zip.setEditable(false);
395             phone.setEditable(false);
396             e.setEditable(false);
397         }
398
399         p2.add(fnamelab);
400         p2.add(fname);
401         p2.add(lnamelab);
402         p2.add(lname);
403         p2.add(milab);
404         p2.add(mi);
405         p2.add(streetlab);
406         p2.add(street);
407         p2.add(citylab);
408         p2.add(city);
409         p2.add(statelab);
410         p2.add(state);
411         p2.add(ziplab);
412         p2.add(zip);
413         p2.add(phonelab);
414         p2.add(phone);
415         p2.add(emaillab);
416         p2.add(e);
417         p2.add(OK);
418         p2.add(cancel);
419         p2.validate();
420         p2.repaint();
421     }
422
423     protected void makeRadioButtons(String JavaDoc type) {
424         //Radio Buttons to choose account type
425
if (type != null) {
426             if (type == "Savings") {
427                 savingsact.setSelected(true);
428             }
429
430             if (type == "Checking") {
431                 checkingact.setSelected(true);
432             }
433
434             if (type == "Credit") {
435                 creditact.setSelected(true);
436             }
437
438             if (type == "Money Market") {
439                 mnymktact.setSelected(true);
440             }
441         } else {
442             this.savingsact =
443                 new JRadioButton(messages.getString("SavingsAct"));
444             savingsact.setActionCommand("savingsstring");
445             savingsact.setSelected(false);
446
447             this.checkingact =
448                 new JRadioButton(messages.getString("CheckingAct"));
449             checkingact.setActionCommand("checkingstring");
450             checkingact.setSelected(false);
451
452             this.creditact = new JRadioButton(messages.getString("CreditAct"));
453             creditact.setActionCommand("creditstring");
454             creditact.setSelected(false);
455
456             this.mnymktact = new JRadioButton(messages.getString("MnyMktAct"));
457             mnymktact.setActionCommand("mnymktstring");
458             mnymktact.setSelected(false);
459
460             this.group = new ButtonGroup();
461         }
462
463         savingsact.addActionListener(ehandle);
464         checkingact.addActionListener(ehandle);
465         creditact.addActionListener(ehandle);
466         mnymktact.addActionListener(ehandle);
467
468         group.add(savingsact);
469         group.add(checkingact);
470         group.add(creditact);
471         group.add(mnymktact);
472
473         radioPanel = new JPanel();
474         radioPanel.setLayout(new GridLayout JavaDoc(0, 1));
475         radioPanel.add(this.savingsact);
476         radioPanel.add(this.checkingact);
477         radioPanel.add(this.creditact);
478         radioPanel.add(this.mnymktact);
479     }
480
481     protected void createActFields(boolean readonly, String JavaDoc type,
482         BigDecimal JavaDoc bal, BigDecimal JavaDoc creditline, BigDecimal JavaDoc begbalance,
483         ArrayList JavaDoc alist, Date JavaDoc timestamp) {
484         p2.removeAll();
485         createPanelTwoActLabels();
486
487         String JavaDoc custIDs = null;
488         NumberFormat JavaDoc numFormat = NumberFormat.getNumberInstance(currentLocale);
489
490         if (alist.size() != 0) {
491             custIDs = alist.toString();
492             this.cust = new JTextField(custIDs);
493         } else {
494             this.cust = new JTextField();
495         }
496
497         this.descrip = new JTextField(this.desc);
498         this.type = new JTextField(type);
499
500         //Internationalize date
501
String JavaDoc viewtime = DateFormat.getDateInstance()
502                                     .format(timestamp);
503         this.time = new JTextField(viewtime);
504
505         //Internationalize numbers
506
String JavaDoc balstring = numFormat.format(bal.doubleValue());
507         this.bal = new JTextField(balstring);
508
509         String JavaDoc creditstring = numFormat.format(creditline.doubleValue());
510         this.credit = new JTextField(creditstring);
511
512         String JavaDoc begbalstring = numFormat.format(begbalance.doubleValue());
513         this.begbal = new JTextField(begbalstring);
514
515         //Listen for Return action event
516
this.begbal.addActionListener(ehandle);
517
518         if (readonly == false) {
519             makeRadioButtons(type);
520             p2.add(this.typelab);
521             p2.add(this.radioPanel);
522
523             //Read-only part of display
524
this.bal.setEditable(false);
525             this.time.setEditable(false);
526         } else if (readonly == true) {
527             this.type.setEditable(false);
528             p2.add(this.typelab);
529             p2.add(this.type);
530             this.descrip.setEditable(false);
531             this.type.setEditable(false);
532             this.credit.setEditable(false);
533             this.begbal.setEditable(false);
534             this.bal.setEditable(false);
535             this.cust.setEditable(false);
536             this.time.setEditable(false);
537         }
538
539         p2.add(this.descriplab);
540         p2.add(this.descrip);
541         p2.add(this.timelab);
542         p2.add(this.time);
543         p2.add(this.balab);
544         p2.add(this.bal);
545         p2.add(this.creditlab);
546         p2.add(this.credit);
547         p2.add(this.begbalab);
548         p2.add(this.begbal);
549         p2.add(this.customerlab);
550         p2.add(this.cust);
551         p2.add(OK);
552         p2.add(cancel);
553         p2.validate();
554         p2.repaint();
555     }
556
557     public static void main(String JavaDoc[] args) {
558         String JavaDoc language;
559         String JavaDoc country;
560
561         if (args.length == 1) {
562             language = new String JavaDoc(args[0]);
563             currentLocale = new Locale JavaDoc(language, "");
564         } else if (args.length == 2) {
565             language = new String JavaDoc(args[0]);
566             country = new String JavaDoc(args[1]);
567             currentLocale = new Locale JavaDoc(language, country);
568         } else {
569             currentLocale = Locale.getDefault();
570         }
571
572         frame = new BankAdmin(currentLocale);
573         frame.setTitle(messages.getString("CustAndAccountAdmin"));
574
575         WindowListener JavaDoc l =
576             new WindowAdapter JavaDoc() {
577                 public void windowClosing(WindowEvent JavaDoc e) {
578                     System.exit(0);
579                 }
580             };
581
582         frame.addWindowListener(l);
583         frame.pack();
584         frame.setVisible(true);
585
586         //Create event handling object
587
ehandle = new EventHandle(frame, messages);
588     }
589 }
590
Popular Tags