1 27 28 29 package com.sun.ebank.appclient; 30 31 import java.util.Locale ; 32 import java.util.ResourceBundle ; 33 import java.text.NumberFormat ; 34 import java.text.DateFormat ; 35 import java.io.File ; 36 import java.io.RandomAccessFile ; 37 import java.io.FileNotFoundException ; 38 import java.io.IOException ; 39 import java.util.ArrayList ; 40 import java.util.Date ; 41 import java.math.BigDecimal ; 42 import java.awt.GridLayout ; 43 import java.awt.Color ; 44 import java.awt.event.WindowAdapter ; 45 import java.awt.event.WindowListener ; 46 import java.awt.event.WindowEvent ; 47 import java.awt.event.KeyEvent ; 48 import javax.swing.*; 49 50 51 public class BankAdmin extends JFrame { 52 protected static BankAdmin frame; 54 protected static EventHandle ehandle; 55 56 private static Locale currentLocale = null; 58 protected static ResourceBundle messages = null; 59 protected String 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 protected JTextField fname; 108 109 protected JTextField lname; 111 112 protected JTextField mi; 114 115 protected JTextField street; 117 118 protected JTextField city; 120 121 protected JTextField state; 123 124 protected JTextField account; 126 127 protected JTextField customer; 129 130 protected JTextField zip; 132 133 protected JTextField phone; 135 136 protected JTextField e; 138 139 protected JTextField descrip; 141 142 protected JTextField type; 144 145 protected JTextField bal; 147 148 protected JTextField credit; 150 151 protected JTextField begbal; 153 154 protected JTextField cust; 156 157 protected JTextField time; 159 160 public BankAdmin(Locale currentLocale) { 162 messages = 164 ResourceBundle.getBundle("appclient.AdminMessages", currentLocale); 165 166 getContentPane() 168 .setLayout(new GridLayout (1, 2)); 169 p1 = new JPanel(); 170 p1.setLayout(new GridLayout (20, 1)); 171 p2 = new JPanel(); 172 p2.setLayout(new GridLayout (0, 2)); 173 p1.setBackground(Color.white); 174 p2.setBackground(Color.gray); 175 getContentPane() 176 .add(p1); 177 getContentPane() 178 .add(p2); 179 180 mb = new JMenuBar(); 182 setJMenuBar(mb); 183 184 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 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 OK = new JButton(messages.getString("OKButton")); 221 cancel = new JButton(messages.getString("CancelButton")); 222 223 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 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 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 spacerlab1 = new JLabel("_____________________________"); 257 spacerlab2 = new JLabel("_____________________________"); 258 259 p2.add(spacerlab1); 261 p2.add(spacerlab2); 262 263 this.descrip = new JTextField(); 265 266 addWindowListener(new WindowAdapter () { 268 public void windowClosing(WindowEvent 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 text) { 337 this.desc = text; 338 339 if (text != null) { 340 this.descrip.setText(this.desc); 341 } 342 } 343 344 protected void addCustToActFields(String custID, String 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 first, 373 String last, String mid, String str, String cty, String st, String zp, 374 String tel, String 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 type) { 424 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 (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 type, 482 BigDecimal bal, BigDecimal creditline, BigDecimal begbalance, 483 ArrayList alist, Date timestamp) { 484 p2.removeAll(); 485 createPanelTwoActLabels(); 486 487 String custIDs = null; 488 NumberFormat 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 String viewtime = DateFormat.getDateInstance() 502 .format(timestamp); 503 this.time = new JTextField(viewtime); 504 505 String balstring = numFormat.format(bal.doubleValue()); 507 this.bal = new JTextField(balstring); 508 509 String creditstring = numFormat.format(creditline.doubleValue()); 510 this.credit = new JTextField(creditstring); 511 512 String begbalstring = numFormat.format(begbalance.doubleValue()); 513 this.begbal = new JTextField(begbalstring); 514 515 this.begbal.addActionListener(ehandle); 517 518 if (readonly == false) { 519 makeRadioButtons(type); 520 p2.add(this.typelab); 521 p2.add(this.radioPanel); 522 523 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 [] args) { 558 String language; 559 String country; 560 561 if (args.length == 1) { 562 language = new String (args[0]); 563 currentLocale = new Locale (language, ""); 564 } else if (args.length == 2) { 565 language = new String (args[0]); 566 country = new String (args[1]); 567 currentLocale = new Locale (language, country); 568 } else { 569 currentLocale = Locale.getDefault(); 570 } 571 572 frame = new BankAdmin(currentLocale); 573 frame.setTitle(messages.getString("CustAndAccountAdmin")); 574 575 WindowListener l = 576 new WindowAdapter () { 577 public void windowClosing(WindowEvent e) { 578 System.exit(0); 579 } 580 }; 581 582 frame.addWindowListener(l); 583 frame.pack(); 584 frame.setVisible(true); 585 586 ehandle = new EventHandle(frame, messages); 588 } 589 } 590 | Popular Tags |