Developing the Bank Checking Account MTS Client
Gopalan Suresh Raj

 

Note
To work with any of these samples, you will need the following:
.........................................Microsoft Visual J++ ver 6.0
.........................................Windows NT 4.0 Options Pack

The CheckingClient is used to access the CheckingServer and manage Checking accounts.


Figure : Shows the CheckingClient MTS client program in action

The Steps involved in developing the MTS Client are

1. Create a new Windows Application
2. Add COM Wrappers for the Java MTS Server Component
3. Add code in the Client to call the MTS Server
4. Build and Run the Client

A Three Tier Architecture for a typical Bank Account

Figure shows what we are trying to ultimately accomplish in these pages

1. Create a new Windows Application
Create a Windows Application project in Visual J++ by selecting the New Project in the File menu, then choosing the Windows Application project template. Name the project ClickClient and choose Open.

2. Add COM Wrappers for the BankServer Java MTS Component
Set up COM access to the Java Client App by adding COM wrappers to the server component. From the Project menu, select Add COM wrapper. Select the checkbox next to the Bank in the list of installed COM components in the COM Wrappers dialog and press OK. You will notice a package called Bank added to the CheckingClient project. Alternatively, if the Bank does not show up on the list of registered COM wrappers, you always have the option of browsing and selecting the DLL manually.

3. Add code in the CheckingClient to call the BankServer Java MTS component
This is where we add code to the Client apps form to interact with the Java MTS BankServer component. Create a form similar to the one shown.


Figure : Shows the form that we need to develop for our CheckingClient program

Now add code to the generated source. The completed code is shown below:

CheckingClient.java
import com.ms.wfc.app.*;
import com.ms.wfc.core.*;
import com.ms.wfc.ui.*;
import com.ms.wfc.html.*;
import com.ms.com.*;

import bank.*;

/**
 * This class can take a variable number of parameters on the command
 * line. Program execution begins with the main() method. The class
 * constructor is not invoked unless an object of type 'CheckingClient'
 * created in the main() method.
 * @com.register ( clsid=DD5AF92C-FBA4-11D2-97E4-006097A7D34F, typelib=DD5AF92B-FBA4-11D2-97E4-006097A7D34F )
 */

public class CheckingClient extends Form {
 
 static final int INITIAL_RECORD = 11;
 
 int    accountNo;
 String name;
 double balance;
 int    count;

 
 public CheckingClient () {
  super();
  // Required for Visual J++ Form Designer support
  initForm();
  fillAccountList ();
 }

 /**
  * CheckingClient overrides dispose so it can clean up the
  * component list.
  */

 public void dispose() {
  super.dispose();
  components.dispose();
 }

 public void fillAccountList() {
  accountList.removeAll ();
  count = 0;
  boolean bMoreElements = true;
  do {
   try {
   bank.IChecking server= (bank.IChecking)new bank.Checking ();
   bank.IAccountKey key = (bank.IAccountKey)new bank.CheckingPK ();
    key.setKey (count+INITIAL_RECORD);
 
    name = server.getCustomerName (key);

    if(name == null)
     break;
 
    accountList.addItem ((new Integer (count+INITIAL_RECORD)).toString ());
 
    key = null;
    server = null;
   }
   catch (Exception ex) {
    ex.printStackTrace ();
    bMoreElements = false;
   }
   ++count;
  } while (bMoreElements == true);
 }

 private void retrieveButton_click(Object source, Event e) {
 
  if (accountList.getSelectedItem () == null)
   return;
 
  String accSel = (accountList.getSelectedItem ()).toString ();
  accountNo = (new Integer (accSel)).intValue ();
 
  try {
   bank.IChecking server= (bank.IChecking)new bank.Checking ();
   bank.IAccountKey key = (bank.IAccountKey)new bank.CheckingPK ();

 
   key.setKey (accountNo);
   balance = server.getBalance (key);
   name = server.getCustomerName (key);
 

   numberEdit.setText ( (new Integer (accountNo)).toString () );
   nameEdit.setText (name);
   balanceEdit.setText ( (new Double (balance)).toString () );
 
   key = null;
   server = null;
  }
  catch (Exception ex) {
   ex.printStackTrace ();
  }
 }

 private void addButton_click(Object source, Event e) {
 
  accountNo = count+INITIAL_RECORD;
  name = nameEdit.getText ();
  balance = ( new Double (balanceEdit.getText ()) ).doubleValue ();
 
  if ((accountNo == 0) || (name == null))
   return;
 
  try {
   bank.ICheckingHome server= (bank.ICheckingHome)new bank.Checking ();
   bank.IAccountKey key = (bank.IAccountKey)new bank.CheckingPK ();
   key.setKey (accountNo);
 
   server.create (key, name, balance);

  }
  catch (Exception ex) {
   ex.printStackTrace ();
  }
 
  fillAccountList ();
 }

 private void closeButton_click(Object source, Event e) {
  Application.exit ();
 }

 private void creditButton_click(Object source, Event e) {
  if (accountList.getSelectedItem () == null)
   return;
 
  String accSel = (accountList.getSelectedItem ()).toString ();
  accountNo = (new Integer (accSel)).intValue ();
 
  double amount = ( new Double (creditEdit.getText ()) ).doubleValue ();
 
  try {
   bank.IChecking server= (bank.IChecking)new bank.Checking ();
   bank.IAccountKey key = (bank.IAccountKey)new bank.CheckingPK ();
   key.setKey (accountNo);
 
   server.credit (amount, key);
   balance = server.getBalance (key);
   name = server.getCustomerName (key);

 
   numberEdit.setText ( (new Integer (accountNo)).toString () );
   nameEdit.setText (name);
   balanceEdit.setText ( (new Double (balance)).toString () );
 
   key = null;
   server = null;
  }
  catch (Exception ex) {
   ex.printStackTrace ();
  }
 }

 private void debitButton_click(Object source, Event e) {
  if (accountList.getSelectedItem () == null)
   return;
 
  String accSel = (accountList.getSelectedItem ()).toString ();
  accountNo = (new Integer (accSel)).intValue ();
 
  double amount = ( new Double (debitEdit.getText ()) ).doubleValue ();
 
  try {
   bank.IChecking server= (bank.IChecking)new bank.Checking ();
   bank.IAccountKey key = (bank.IAccountKey)new bank.CheckingPK ();
   key.setKey (accountNo);
 
   server.debit (amount, key);
   balance = server.getBalance (key);
   name = server.getCustomerName (key);

 
   numberEdit.setText ( (new Integer (accountNo)).toString () );
   nameEdit.setText (name);
   balanceEdit.setText ( (new Double (balance)).toString () );
 
   key = null;
   server = null;
  }
  catch (Exception ex) {
   ex.printStackTrace ();
  }
 }

 /**
  * NOTE: The following code is required by the Visual J++ form
  * designer.  It can be modified using the form editor.  Do not
  * modify it using the code editor.
  */

 Container components = new Container();
 ListBox accountList = new ListBox();
 Button retrieveButton = new Button();
 Button closeButton = new Button();
 Button addButton = new Button();
 Edit numberEdit = new Edit();
 Edit nameEdit = new Edit();
 Edit balanceEdit = new Edit();
 Label label1 = new Label();
 Label label2 = new Label();
 Label label3 = new Label();
 Edit creditEdit = new Edit();
 Edit debitEdit = new Edit();
 Button creditButton = new Button();
 Button debitButton = new Button();

 private void initForm() {
  this.setText("CheckingClient");
  this.setAutoScaleBaseSize(new Point(5, 13));
  this.setClientSize(new Point(300, 336));

  accountList.setAllowDrop(true);
  accountList.setLocation(new Point(16, 216));
  accountList.setSize(new Point(128, 108));
  accountList.setTabIndex(0);
  accountList.setText("listBox1");
  accountList.setUseTabStops(true);

  retrieveButton.setLocation(new Point(184, 240));
  retrieveButton.setSize(new Point(96, 24));
  retrieveButton.setTabIndex(5);
  retrieveButton.setText("Retrieve");
  retrieveButton.addOnClick(new EventHandler(this.retrieveButton_click));

  closeButton.setLocation(new Point(184, 280));
  closeButton.setSize(new Point(96, 24));
  closeButton.setTabIndex(4);
  closeButton.setText("Close");
  closeButton.addOnClick(new EventHandler(this.closeButton_click));

  addButton.setLocation(new Point(96, 112));
  addButton.setSize(new Point(96, 24));
  addButton.setTabIndex(3);
  addButton.setText("Add Record");
  addButton.addOnClick(new EventHandler(this.addButton_click));

  numberEdit.setLocation(new Point(120, 16));
  numberEdit.setSize(new Point(160, 20));
  numberEdit.setTabIndex(10);
  numberEdit.setText("-1");
  numberEdit.setReadOnly(true);

  nameEdit.setLocation(new Point(120, 48));
  nameEdit.setSize(new Point(160, 20));
  nameEdit.setTabIndex(9);
  nameEdit.setText("Nobody");

  balanceEdit.setLocation(new Point(120, 80));
  balanceEdit.setSize(new Point(160, 20));
  balanceEdit.setTabIndex(7);
  balanceEdit.setText("-1.0");

  label1.setLocation(new Point(16, 16));
  label1.setSize(new Point(88, 16));
  label1.setTabIndex(13);
  label1.setTabStop(false);
  label1.setText("Account Number");

  label2.setLocation(new Point(16, 48));
  label2.setSize(new Point(88, 16));
  label2.setTabIndex(12);
  label2.setTabStop(false);
  label2.setText("Customer Name");

  label3.setLocation(new Point(16, 80));
  label3.setSize(new Point(88, 16));
  label3.setTabIndex(11);
  label3.setTabStop(false);
  label3.setText("Balance (in US $)");

  creditEdit.setLocation(new Point(16, 152));
  creditEdit.setSize(new Point(128, 20));
  creditEdit.setTabIndex(8);
  creditEdit.setText("0");

  debitEdit.setLocation(new Point(16, 184));
  debitEdit.setSize(new Point(128, 20));
  debitEdit.setTabIndex(6);
  debitEdit.setText("0");

  creditButton.setLocation(new Point(184, 152));
  creditButton.setSize(new Point(96, 24));
  creditButton.setTabIndex(2);
  creditButton.setText("Credit (in US $)");
  creditButton.addOnClick(new EventHandler(this.creditButton_click));

  debitButton.setLocation(new Point(184, 184));
  debitButton.setSize(new Point(96, 24));
  debitButton.setTabIndex(1);
  debitButton.setText("Debit (in US $)");
  debitButton.addOnClick(new EventHandler(this.debitButton_click));

  this.setNewControls(new Control[] {
                      debitEdit,
                      debitButton,
                      creditButton,
                      creditEdit,
                      label3,
                      label2,
                      label1,
                      balanceEdit,
                      nameEdit,
                      numberEdit,
                      addButton,
                      closeButton,
                      retrieveButton,
                      accountList});
 }

 /**
  * The main entry point for the application.
  *
  * @param args Array of parameters passed to the application
  * via the command line.
  */

 public static void main (String args[]) {
  Application.run (new CheckingClient ());
 }
}

4. Build and Run the Client program - CheckingClient
Build the project by selecting Build from the Build menu. This creates a Windows executable with all the class files needed to execute the client including the COM wrappers for the server - packaged into one executable. Run it and have fun...

click here to go to the
Developing the Checking Account MTS Server Component Page...
click here to go to
My MTS HomePage...

Go to the Component Engineering Cornucopia page

This site was developed and is maintained by Gopalan Suresh Raj

This page has been visited times since April 26,1999.

Last Updated : Apr 26, '99

If you have any questions, comments, or problems regarding this site, please write to me I would love to hear from you.


Copyright (c) 1997-99, Gopalan Suresh Raj - All rights reserved. Terms of use.

All products and companies mentioned at this site,are trademarks of their respective owners.