1 27 28 29 package com.sun.ebank.appclient; 30 31 import java.util.ResourceBundle ; 32 import java.util.ResourceBundle ; 33 import java.awt.event.ActionListener ; 34 import java.awt.event.ActionEvent ; 35 import javax.swing.*; 36 import java.awt.Color ; 37 import java.util.ArrayList ; 38 import java.util.Date ; 39 40 41 public class EventHandle implements ActionListener { 42 private static BankAdmin frame; 43 private ResourceBundle messages = null; 44 private DataModel dataModel; 45 private String returned; 46 private int currentFunction; 47 48 public EventHandle(BankAdmin frame, ResourceBundle messages) { 49 this.frame = frame; 50 this.messages = messages; 51 this.dataModel = new DataModel(frame, messages); 52 53 hookupEvents(); 55 } 56 57 public void actionPerformed(ActionEvent event) { 59 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 Object source = event.getSource(); 79 80 if (source == frame.begbal) { 81 String 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 frame.viewcust.addActionListener(new ActionListener () { 95 public void actionPerformed(ActionEvent ev) { 96 setDisplay(); 97 frame.clearMessages(); 98 99 String vitem = messages.getString("ViewCust"); 100 frame.messlab6.setText(vitem); 101 102 String mess = 103 new String (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 frame.createcust.addActionListener(new ActionListener () { 115 public void actionPerformed(ActionEvent ev) { 116 setDisplay(); 117 frame.clearMessages(); 118 119 String citem = messages.getString("CreateCust"); 120 frame.messlab6.setText(citem); 121 currentFunction = 1; 122 dataModel.createCustInf(currentFunction, returned); 123 } 124 }); 125 126 frame.updatecust.addActionListener(new ActionListener () { 128 public void actionPerformed(ActionEvent ev) { 129 setDisplay(); 130 frame.clearMessages(); 131 132 String uitem = messages.getString("UpdateCust"); 133 frame.messlab6.setText(uitem); 134 135 String mess = 136 new String (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 frame.viewact.addActionListener(new ActionListener () { 148 public void actionPerformed(ActionEvent ev) { 149 setDisplay(); 150 frame.clearMessages(); 151 152 String vitem = messages.getString("ViewAct"); 153 frame.messlab6.setText(vitem); 154 155 String mess = 156 new String (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 frame.createact.addActionListener(new ActionListener () { 168 public void actionPerformed(ActionEvent ev) { 169 setDisplay(); 170 frame.clearMessages(); 171 172 String citem = messages.getString("CreateAct"); 173 frame.messlab6.setText(citem); 174 currentFunction = 5; 175 dataModel.createActInf(currentFunction, returned); 176 } 177 }); 178 179 frame.addcust.addActionListener(new ActionListener () { 181 public void actionPerformed(ActionEvent ev) { 182 setDisplay(); 183 frame.clearMessages(); 184 185 String aitem = messages.getString("AddCust"); 186 frame.messlab6.setText(aitem); 187 currentFunction = 6; 188 frame.addCustToActFields(null, null); 189 } 190 }); 191 192 frame.remact.addActionListener(new ActionListener () { 194 public void actionPerformed(ActionEvent ev) { 195 setDisplay(); 196 frame.clearMessages(); 197 198 String ritem = messages.getString("RemAct"); 199 frame.messlab6.setText(ritem); 200 201 String mess = 202 new String (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 frame.srchcust.addActionListener(new ActionListener () { 214 public void actionPerformed(ActionEvent ev) { 215 setDisplay(); 216 frame.clearMessages(); 217 218 String sitem = messages.getString("SearchCust"); 219 frame.messlab6.setText(sitem); 220 221 String mess = 222 new String (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 frame.cancel.addActionListener(new ActionListener () { 234 public void actionPerformed(ActionEvent ev) { 235 setDisplay(); 236 frame.resetPanelTwo(); 237 frame.clearMessages(); 238 } 239 }); 240 241 frame.OK.addActionListener(new ActionListener () { 243 public void actionPerformed(ActionEvent ev) { 244 setDisplay(); 245 246 if (currentFunction == 3) { frame.resetPanelTwo(); 248 } 249 250 if (currentFunction < 3) { 252 int complete = 254 dataModel.checkCustData(returned, currentFunction); 255 256 if (complete == 0) { 258 if (currentFunction == 1) { 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 (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) { frame.resetPanelTwo(); 288 frame.clearMessages(); 289 } 290 291 if (currentFunction > 4) { 293 int complete = 294 dataModel.checkActData(returned, currentFunction); 295 296 if (complete == 0) { 297 if (currentFunction == 5) { 299 frame.resetPanelTwo(); 301 frame.clearMessages(); 302 JOptionPane.showMessageDialog(frame, 303 dataModel.actID, "Account ID", 304 JOptionPane.PLAIN_MESSAGE); 305 } 306 307 if (currentFunction == 6) { 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) { frame.setDescription(dataModel.descrip); 320 321 boolean readonly = false; 322 Date timestamp = new Date (); 323 ArrayList alist = new ArrayList (); 324 frame.createActFields(readonly, dataModel.type, 325 dataModel.balance, dataModel.creditline, 326 dataModel.beginbalance, alist, timestamp); 327 frame.cust.setText(dataModel.custID); 328 } else { frame.addCustToActFields(dataModel.custID, 330 dataModel.actID); 331 } 332 } 333 } 334 } 335 }); 336 } 337 } 338 | Popular Tags |