Library Zone Articles
External Articles
Byte Size

Discovery Zone Catalogue
Diary
Links
Bookstore
Interactive Zone Ask the Gurus
Discussion Groups
Newsletters
Feedback
Etc Cartoons
Humour
COMpetition
Advertising
Site Builder ASP Web Ring ASP Web Ring

Power your site with idr newswire
The Developer's Resource & Community Site
COM XML ASP Java & Misc. NEW: VS.NET
International This Week Forums Author Central Find a Job

Three-Tier Architecture for a Bank Checking Account - MTS Client

The source code for this example is available as a zip file for download here.

Previous Page....MTS Server Component

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.

Shows the CheckingClient MTS client program in action
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
A Three Tier Architecture for a typical Bank Account

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.

Shows the form that we need to develop for our CheckingClient program
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...


What do you think of this article?

Have your say about the article. You can make your point about the article by mailing [email protected] (If you haven't allready joined, you can join by going to https://www.onelist.com/community/dev-java).

You can also write a review. We will publish the best ones here on this article. Send your review to [email protected]. Please include the title of the article you are reviewing.

Further Reading

The MTS Series by Gopalan Suresh Raj:

Microsoft Transaction Server By Gopalan Suresh Raj.
Gopalans introductory article on Microsoft Transaction Server intorduces the basics to MTS, and leads in to the example articles included in the series.

Developing a Simple MTS Server Component By Gopalan Suresh Raj.
Part 1 of a two part example.

Developing a Simple MTS Client Application By Gopalan Suresh Raj.
Part 2 of a two part example.

Developing The Bank Account IDL By Gopalan Suresh Raj.
A Three-Tier Architecture for a Bank Checking Account - Developing The Bank Account IDL is part 1 of a 3 part example.

MTS Server Component By Gopalan Suresh Raj.
A Three-Tier Architecture for a Bank Checking Account - MTS Server Component is the second part of this three part example.


Author: Gopalan Suresh Raj

You can meet Gopalan, and the other iDevResource authors in Author Central. Gopalan also maintains his own site at https://www.execpc.com/~gopalan/.

Contributors to iDevResource.com get their own site at Author Central. Why not write an article and become a member of the iDevResource community.

© Copyright 1997-2000 Gopalan Suresh Raj. Reproduced with Permission


Power your site with idr newswire

Contribute to IDR:

To contribute an article to IDR, a click here.

To contact us at IDevResource.com, use our feedback form, or email us.

To comment on the site contact our webmaster.

Promoted by CyberSavvy UK - website promotion experts

All content © Copyright 2000 IDevResource.com, Disclaimer notice

Code Project

Join the Developers Webring



Visit the IDR Bookstore!

WTL Architecture by Richard Grimes