KickJava   Java API By Example, From Geeks To Geeks.

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


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.ResourceBundle JavaDoc;
32 import java.util.ResourceBundle JavaDoc;
33 import java.awt.event.ActionListener JavaDoc;
34 import java.awt.event.ActionEvent JavaDoc;
35 import javax.swing.*;
36 import java.awt.Color JavaDoc;
37 import java.util.ArrayList JavaDoc;
38 import java.util.Date JavaDoc;
39
40
41 public class EventHandle implements ActionListener JavaDoc {
42     private static BankAdmin frame;
43     private ResourceBundle JavaDoc messages = null;
44     private DataModel dataModel;
45     private String JavaDoc returned;
46     private int currentFunction;
47
48     public EventHandle(BankAdmin frame, ResourceBundle JavaDoc messages) {
49         this.frame = frame;
50         this.messages = messages;
51         this.dataModel = new DataModel(frame, messages);
52
53         //Hook up action events
54
hookupEvents();
55     }
56
57     //Respond to radio button and return key action events
58
public void actionPerformed(ActionEvent JavaDoc event) {
59         //Set Account description according to radio buttons
60
if (event.getActionCommand() == "savingsstring") {
61             frame.setDescription("Savings");
62         }
63
64         if (event.getActionCommand() == "checkingstring") {
65             frame.setDescription("Checking");
66         }
67
68         if (event.getActionCommand() == "creditstring") {
69             frame.setDescription("Credit");
70         }
71
72         if (event.getActionCommand() == "mnymktstring") {
73             frame.setDescription("Money Market");
74         }
75
76         //Set balance to beginning balance for new accounts
77
//when return key pressed in begining balance field
78
Object JavaDoc source = event.getSource();
79
80         if (source == frame.begbal) {
81             String JavaDoc begbalstring = frame.begbal.getText();
82             frame.bal.setText(begbalstring);
83         }
84     }
85
86     private void setDisplay() {
87         frame.p2.setBackground(Color.white);
88         frame.spacerlab1.setText("");
89         frame.spacerlab2.setText("");
90     }
91
92     private void hookupEvents() {
93         //View Customer Information
94
frame.viewcust.addActionListener(new ActionListener JavaDoc() {
95                 public void actionPerformed(ActionEvent JavaDoc ev) {
96                     setDisplay();
97                     frame.clearMessages();
98
99                     String JavaDoc vitem = messages.getString("ViewCust");
100                     frame.messlab6.setText(vitem);
101
102                     String JavaDoc mess =
103                         new String JavaDoc(messages.getString("EnterCustIDMess"));
104                     returned = JOptionPane.showInputDialog(frame, mess);
105
106                     if (returned != null) {
107                         currentFunction = 3;
108                         dataModel.createCustInf(currentFunction, returned);
109                     }
110                 }
111             });
112
113         //Create New Customer
114
frame.createcust.addActionListener(new ActionListener JavaDoc() {
115                 public void actionPerformed(ActionEvent JavaDoc ev) {
116                     setDisplay();
117                     frame.clearMessages();
118
119                     String JavaDoc citem = messages.getString("CreateCust");
120                     frame.messlab6.setText(citem);
121                     currentFunction = 1;
122                     dataModel.createCustInf(currentFunction, returned);
123                 }
124             });
125
126         //Update Customer Information
127
frame.updatecust.addActionListener(new ActionListener JavaDoc() {
128                 public void actionPerformed(ActionEvent JavaDoc ev) {
129                     setDisplay();
130                     frame.clearMessages();
131
132                     String JavaDoc uitem = messages.getString("UpdateCust");
133                     frame.messlab6.setText(uitem);
134
135                     String JavaDoc mess =
136                         new String JavaDoc(messages.getString("EnterCustIDMess"));
137                     returned = JOptionPane.showInputDialog(frame, mess);
138
139                     if (returned != null) {
140                         currentFunction = 2;
141                         dataModel.createCustInf(currentFunction, returned);
142                     }
143                 }
144             });
145
146         //View Account Information
147
frame.viewact.addActionListener(new ActionListener JavaDoc() {
148                 public void actionPerformed(ActionEvent JavaDoc ev) {
149                     setDisplay();
150                     frame.clearMessages();
151
152                     String JavaDoc vitem = messages.getString("ViewAct");
153                     frame.messlab6.setText(vitem);
154
155                     String JavaDoc mess =
156                         new String JavaDoc(messages.getString("EnterActIDMess"));
157                     returned = JOptionPane.showInputDialog(frame, mess);
158
159                     if (returned != null) {
160                         currentFunction = 4;
161                         dataModel.createActInf(currentFunction, returned);
162                     }
163                 }
164             });
165
166         //Create New Account
167
frame.createact.addActionListener(new ActionListener JavaDoc() {
168                 public void actionPerformed(ActionEvent JavaDoc ev) {
169                     setDisplay();
170                     frame.clearMessages();
171
172                     String JavaDoc citem = messages.getString("CreateAct");
173                     frame.messlab6.setText(citem);
174                     currentFunction = 5;
175                     dataModel.createActInf(currentFunction, returned);
176                 }
177             });
178
179         //Add Customer to Account
180
frame.addcust.addActionListener(new ActionListener JavaDoc() {
181                 public void actionPerformed(ActionEvent JavaDoc ev) {
182                     setDisplay();
183                     frame.clearMessages();
184
185                     String JavaDoc aitem = messages.getString("AddCust");
186                     frame.messlab6.setText(aitem);
187                     currentFunction = 6;
188                     frame.addCustToActFields(null, null);
189                 }
190             });
191
192         //Remove Account
193
frame.remact.addActionListener(new ActionListener JavaDoc() {
194                 public void actionPerformed(ActionEvent JavaDoc ev) {
195                     setDisplay();
196                     frame.clearMessages();
197
198                     String JavaDoc ritem = messages.getString("RemAct");
199                     frame.messlab6.setText(ritem);
200
201                     String JavaDoc mess =
202                         new String JavaDoc(messages.getString("EnterActIDMess"));
203                     returned = JOptionPane.showInputDialog(frame, mess);
204
205                     if (returned != null) {
206                         currentFunction = 7;
207                         dataModel.removeAccount(returned);
208                     }
209                 }
210             });
211
212         //Search for Customer ID by last name
213
frame.srchcust.addActionListener(new ActionListener JavaDoc() {
214                 public void actionPerformed(ActionEvent JavaDoc ev) {
215                     setDisplay();
216                     frame.clearMessages();
217
218                     String JavaDoc sitem = messages.getString("SearchCust");
219                     frame.messlab6.setText(sitem);
220
221                     String JavaDoc mess =
222                         new String JavaDoc(messages.getString("EnterLastNameMess"));
223                     returned = JOptionPane.showInputDialog(frame, mess);
224
225                     if (returned != null) {
226                         currentFunction = 8;
227                         dataModel.searchByLastName(returned);
228                     }
229                 }
230             });
231
232         //Clear data on cancel button press
233
frame.cancel.addActionListener(new ActionListener JavaDoc() {
234                 public void actionPerformed(ActionEvent JavaDoc ev) {
235                     setDisplay();
236                     frame.resetPanelTwo();
237                     frame.clearMessages();
238                 }
239             });
240
241         //Process data
242
frame.OK.addActionListener(new ActionListener JavaDoc() {
243                 public void actionPerformed(ActionEvent JavaDoc ev) {
244                     setDisplay();
245
246                     if (currentFunction == 3) { //view customer data
247
frame.resetPanelTwo();
248                     }
249
250                     if (currentFunction < 3) { //Create or update customer data
251

252                         //Test data and write to database
253
int complete =
254                             dataModel.checkCustData(returned, currentFunction);
255
256                         //if data okay, clear Panel 2
257
if (complete == 0) {
258                             if (currentFunction == 1) { //Create New Customer
259
JOptionPane.showMessageDialog(frame,
260                                     dataModel.custID, "Customer ID",
261                                     JOptionPane.PLAIN_MESSAGE);
262                                 frame.resetPanelTwo();
263                                 frame.clearMessages();
264                             }
265
266                             if (currentFunction == 2) {
267                                 frame.resetPanelTwo();
268                                 frame.clearMessages();
269                                 frame.messlab2.setText(messages.getString(
270                                         "Customer") + " " + returned + " " +
271                                     messages.getString("Updated"));
272                             }
273                         }
274
275                         //If errors, redisplay data to user
276
//and leave error messages on display
277
if (complete == 1) {
278                             boolean readonly = false;
279                             frame.createCustFields(readonly, dataModel.first,
280                                 dataModel.last, dataModel.mid, dataModel.str,
281                                 dataModel.cty, dataModel.st, dataModel.zp,
282                                 dataModel.tel, dataModel.mail);
283                         }
284                     }
285
286                     if (currentFunction == 4) { //View account info
287
frame.resetPanelTwo();
288                         frame.clearMessages();
289                     }
290
291                     if (currentFunction > 4) { //Create account; add cust to act
292

293                         int complete =
294                             dataModel.checkActData(returned, currentFunction);
295
296                         if (complete == 0) {
297                             if (currentFunction == 5) { //Create New Account
298

299                                 //Return new account ID
300
frame.resetPanelTwo();
301                                 frame.clearMessages();
302                                 JOptionPane.showMessageDialog(frame,
303                                     dataModel.actID, "Account ID",
304                                     JOptionPane.PLAIN_MESSAGE);
305                             }
306
307                             if (currentFunction == 6) { //Add cust to account
308
frame.resetPanelTwo();
309                                 frame.clearMessages();
310                                 frame.messlab2.setText(messages.getString(
311                                         "Customer") + " " + dataModel.custID +
312                                     " " + messages.getString("AddedToAct") +
313                                     " " + dataModel.actID);
314                             }
315                         }
316
317                         if (complete == 1) {
318                             if (currentFunction == 5) { //Create New Account
319
frame.setDescription(dataModel.descrip);
320
321                                 boolean readonly = false;
322                                 Date JavaDoc timestamp = new Date JavaDoc();
323                                 ArrayList JavaDoc alist = new ArrayList JavaDoc();
324                                 frame.createActFields(readonly, dataModel.type,
325                                     dataModel.balance, dataModel.creditline,
326                                     dataModel.beginbalance, alist, timestamp);
327                                 frame.cust.setText(dataModel.custID);
328                             } else { //Add Customer to Account
329
frame.addCustToActFields(dataModel.custID,
330                                     dataModel.actID);
331                             }
332                         }
333                     }
334                 }
335             });
336     }
337 }
338
Popular Tags