Brought to you by EarthWeb
ITKnowledge Logo Login Graphic Click Here!
Click Here!
ITKnowledge
Search this book:
 
Search the site:
 
EXPERT SEARCH ----- nav

EarthWeb Direct

EarthWeb Direct

EarthWeb sites: other sites

Previous Table of Contents Next


NetBank.java

Listing 10-19 contains the source code for NetBank.java.

Listing 10-19: NetBank.java.

  import java.awt.*;
  import java.sql.*;
  import java.lang.*;
  import java.util.*;
  import java.net.*;
  import marimba.gui.*;
  public class NetBank extends java.applet.Applet {
  Presentation presentation;
  PlayerPanel player;
  PlayerUtil util;
  Account curAcct = null;
  float curWithdrawAmount = 0;
  public void init()
  {
    try {
        presentation = Presentation.getPresentation(new
             URL(getDocumentBase(), "netbank.gui"));
    } catch (MalformedURLException ex) {
    ex.printStackTrace();
    }
    // Create a Player Panel
    setLayout(new BorderLayout());
    add("Center", player = new PlayerPanel());
    // Set the presentation
    player.setPresentation(presentation);
    // Create a Player utillity object
    util = new PlayerUtil(player);
    ((FolderWidget)util.getWidget("netbankFolder")).setTabMode(0);

    // Initialize the clock thread
    TimeT t;
    t = new TimeT((TextBoxWidget)util.getWidget("clockLabel"));
    t.start();
}
public void logoutRequest()
{
  util.setText("welcomeAccountNo", "");
  util.setText("welcomePinCode", "");
  util.setText("balanceBalance", "");
  util.setText("balanceHistory", "");
  util.setText("transferAccountNo", "");
  util.setText("transferAmount", "");
  util.setText("statusBar", "");
  curAcct.finalize();
  util.gotoPage("welcomePage");
}
public void displayBalance()
{
  String bal = (new Float(curAcct.checkAcctBalance())).toString();
  util.setText("balanceBalance", bal);
  Vector v = curAcct.checkHistory();
  String s = "";
        for (int i=0; i < v.size(); i++)
        s = s + v.elementAt(i) + "\n";
  util.setText("balanceHistory", s);
  util.setText("statusBar", "");
}
public boolean handleEvent(Event evt)
{
  if ((evt.id == Event.ACTION_EVENT) && (evt.target instanceof
    Widget)) {
  Widget w = (Widget)evt.target;
  String nm = w.getName();
  System.out.println("Event: " + nm);
  // The user has switched pages.
  if (nm.equals("netbankFolder")) {
      util.setText("statusBar", "");
  }
  if (nm.equals("loginPanelButton")) {
      util.gotoPage("welcomePage");
  }
  if (nm.equals("balancePanelButton")) {
      util.gotoPage("balancePage");
  }
  if (nm.equals("transferPanelButton")) {
      util.gotoPage("transferPage");
  }
  if (nm.equals("cashPanelButton")) {
util.gotoPage("withdrawPage");
  }
  // The user has logged in.
  if (nm.equals("welcomeOkButton")) {
      Long acct = new Long(util.getText("welcomeAccountNo").trim());
      String pin = util.getText("welcomePinCode").trim();
      util.setText("statusBar", "Please wait...");
      if ((acct.longValue() > 0) && (pin.length() > 0))
      {
           curAcct = new Account("jdbc:odbc:netbank", "dba", "javabank");
           if (curAcct.verifyPinCode(acct.longValue(), pin))
           {
                    Vector v = curAcct.checkAcctOwnerName(acct.longValue());
                    util.setText("statusBar", "Welcome " + v.elementAt(0) + ", " +
                      v.elementAt(1));
                    util.gotoPage("balancePage");
                    displayBalance();
           }
           else
           {
                    // wrong info
                    util.setText("statusBar", "Account number or PIN invalid!");
                    logoutRequest();
           }
      }
      else
           util.setText("statusBar", "Please enter your account number first!");
}
  // The user has clicked refresh
  if (nm.equals("balanceRefreshButton")) {
           util.setText("statusBar", "Please wait...");
             displayBalance();
  }
  // The user has clicked OK to transfer money
  if (nm.equals("transferYesButton")) {
      Long acct = new Long(util.getText("transferAccountNo").trim());
      Float amnt = new Float(util.getText("transferAmount").trim());
      util.setText("statusBar", "Please wait...");
      if ((acct.longValue() > 0) && (amnt.floatValue() > 0))
      {
           if (0 == 0) // should verify the transferAcctNo
           {
                    curAcct.makeTransfer(acct.longValue(), amnt.floatValue());
                    Vector v = curAcct.checkAcctOwnerName(acct.longValue());
                    util.setText("statusBar", "Transfered to " + v.elementAt(0) + ", " 
                      + v.elementAt(1));
                    util.setText("transferAccountNo", "");
                    util.setText("transferAmount", "");
           }
           else
           {
           // acct does not exist in database
                    util.setText("statusBar", "INVALID ACCT NO OR PIN
                      CODE!!!");
           }
      }
      else
           util.setText("statusBar", "Please enter the account number first!");
  }
  // Check the selection for cash
  if (nm.equals("withdraw20")) {
      curWithdrawAmount = 20;
  } else if (nm.equals("withdraw100")) {
      curWithdrawAmount = 100;
 } else if (nm.equals("withdraw200")) {
      curWithdrawAmount = 200;
 } else if (nm.equals("withdraw1000")) {
      curWithdrawAmount = 1000;
 }
 // The user has clicked withdraw
 if (nm.equals("withdrawWithdrawButton")) {
      util.setText("statusBar", "Please wait.");
      curAcct.cashWithdraw(curWithdrawAmount);
      util.setText("statusBar", "Please wait...");
      ImageWidget img = (ImageWidget) util.getWidget("bankNote");
      img.show();
      for (int i = 0; i < 3050; i++)
      {
           img.reshape(60, 120 - (i / 10), 100, 10 + (i / 10));
           img.repaint();
      }
//img.hide();
  }
  // The user has clicked EndPage to log out
  if (nm.equals("welcomeEndButton")) {
  logoutRequest();
  System.out.println("Ended");
  return true;
  }
 }
 return super.handleEvent(evt);
 }
}

TimeT.java

Listing 10-20 contains the source code for TimeT.java.

Listing 10-20: TimeT.java.

import java.io.*;
import java.lang.*;
import java.util.*;
import marimba.gui.*;
public class TimeT extends Thread {
  private Thread GetTime;
  private boolean bRun;
  TextBoxWidget tbw;
  public TimeT(TextBoxWidget t) {
      tbw = t;
  }
  public void start() {
      bRun = true;
      GetTime = new Thread(this);
      GetTime.start();
  }
  public void run() {
      while(bRun)
      {
           try {GetTime.sleep(1000);}
           catch (InterruptedException e) { }
           String today = (new Date()).toString();
           tbw.setText(today);
      }
  }
}


Previous Table of Contents Next
HomeAbout UsSearchSubscribeAdvertising InfoContact UsFAQs
Use of this site is subject to certain Terms & Conditions.
Copyright (c) 1996-1999 EarthWeb Inc. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.