Make your own free website on

    Developing A Simple MTS Client
Gopalan Suresh Raj


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 ClickClient counts and displays the number of times the User clicks on the "Click Here..." button during the lifetime of this client app. It uses the ClickServer to increment the count (Looks like our ClickClient client program is mathematically challenged :-) !!!!!!!!).

Figure : Shows the ClickClient 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

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 ClickServer 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 ClickServer in the list of installed COM components in the COM Wrappers dialog and press OK. You will notice a package called ClickServer added to the ClickClient project. Alternatively, if the ClickServer 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 ClickClient to call the ClickServer Java MTS component
This is where we add code to the Client apps form to interact with the Java MTS ClickServer component. Create a form similar to the one shown.

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

Now add code to the generated source. The code that needs to be added is highlighted in blue in the figure below. Specifically, we need code to import the ClickServer package
import clickserver.*;

Add a member to cache the Click Count on the client side
 int clickCount = 0;

Add code to the button1_click method so that the server is invoked from the client whenever the button is pressed
 private void button1_click(Object source, Event e)   {
  ClickServer_Dispatch server = (ClickServer_Dispatch)new ClickServer();
  clickCount = server.Increment(clickCount);
  String clickDisplay = "That was click "+clickCount+ " buddy...";


The completed code is shown below:
import clickserver.*;

 * 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 'Form1' is
 * created in the main() method.

public class Form1 extends Form  {

 int clickCount = 0;
 public Form1()  {
  // Required for Visual J++ Form Designer support

  // TODO: Add any constructor code after initForm call

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

 public void dispose()   {

 private void button1_click(Object source, Event e)   {
  ClickServer_Dispatch server = (ClickServer_Dispatch)new ClickServer();
  clickCount = server.Increment(clickCount);
  String clickDisplay = "That was click "+clickCount+ " buddy...";


  * 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();
 Label label1 = new Label();
 Button button1 = new Button();
 PictureBox pictureBox1 = new PictureBox();

 private void initForm()  {
  // NOTE:  This form is storing resource information in an
  // external file.  Do not modify the string parameter to any
  // resources.getObject() function call. For example, do not
  // modify "foo1_location" in the following line of code
  // even if the name of the Foo object changes: 
  //   foo1.setLocation((Point)resources.getObject("foo1_location"));

  IResourceManager resources = new ResourceManager(this, "Form1");
  this.setAutoScaleBaseSize(new Point(5, 13));
  this.setClientSize(new Point(288, 146));

  label1.setLocation(new Point(8, 32));
  label1.setSize(new Point(192, 32));
  label1.setText("Click away to glory buddy");

  button1.setLocation(new Point(96, 96));
  button1.setSize(new Point(88, 23));
  button1.setText("Click Here...");
  button1.addOnClick(new EventHandler(this.button1_click));

  pictureBox1.setLocation(new Point(208, 16));
  pictureBox1.setSize(new Point(100, 50));

  this.setNewControls(new Control[] {

  * 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[])   { Form1());


4. Build and Run the Client program - ClickClient
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 a Simple 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 February 24,1999.

Last Updated : Feb 24, '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.