VJHandShaker: A Tool For Making Easy Java (Core) Interface Design From Visual Basic 6.0

Niladri.Biswas
Posted by in C# category on for Beginner level | Points: 250 | Views : 2400 red flag

VJHandShaker is an attempt to make an easy Java (Core) interface from VB. The software does not provide a full solution to the design development as of now but it presents an easy way to achieve the same.
The software is developed using C#.net 2010.


 Download source code for VJHandShaker: A Tool For Making Easy Java (Core) Interface Design From Visual Basic 6.0

Introduction

Java since it's very inception, has been a good choice for the developers for developing applications. Because of its robustness, platform independentness and fully Object Oriented feature, it adds flavour to the developers. And so is Visual Basic (VB) which is also Object Oriented.

But the most catching feature in VB which Java (Core) is still lacking is it's easiness in making design interface. And a design constitutes an important part in the software development. Without a good look and feel, a software, though may have high functionality, can hardly strive for a long time in the market. So a meticulous design always gives an edge.

Making a complex design in Java as opposed to VB consumes a lot of time. So if the design can be done with accuracy added with rapidness, the development time can be greatly enhanced.

VJHandShaker sets a good focus on the above problem and gives an interesting solution.

Process

VJHandShaker undergoes a number of steps for producing an optimal solution. A schematic diagram (Figure 1) depicted below presents an abstract view about it's working.

A bird's view of the above diagram is presented here.

The rudimentary Form (.frm file) is accepted as the input to the VJHandShaker which is then send to the next phase coined as Data Filtering. The raw data are processed in this phase, relevant properties pertaining to the individual controls (e.g. Textbox, Button etc.) are cropped and are then made ready for the Data Transformation phase's input. Here the informations related to the controls co-ordinate positions that were gathered in the previous steps are tuned inorder to make it appropriate for the java layout. The software has now enough information to give the resultant output i.e. a .java file.

The rest of the article is organized as follows:

  1. Section A describes a detailed view of the various stages of VJHandShaker.
  2. Section B illustrates the working process with detailed examples. It also shows the time taken for the conversation to take.
  3. Section C shows the controls that VJHandShaker has handshake with VB6.0 and J2SDK 1.4 so far.

Section A: Stages Of VJHandShaker1.0

Stage 1: Input Data (.frm file)

Visual Basic’s Form files (.frm) are pure ASCII files which can be viewed by any text editor. A Form file mainly manifests with the control details and the code. The typical structure of the form file is given below:

  1. The version number of the file format.
  2. A block of text containing the form description.
  3. A set of form attributes.
  4. Basic code for the form.

The FRM file introduces itself with version number of the file e.g. VERSION 6.00

The form description contains the form’s properties. The control informations are embedded within the form. Nested controls have their properties nested within the text of the container. In other words, all the controls informations and their properties are embedded within the parent control i.e. Form. The figure below presents the structure of the form description:

A quick walk-through of a typical Form (.frm) file will make the picture clear. Figure 3 shows a form design.

The code generated by the VB editor for the above form is presented below

VERSION 5.00
Begin VB.Form frmMain 
   ClientHeight    =   2010
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   4935
   LinkTopic       =   "Form1"
   ScaleHeight     =   2010
   ScaleWidth      =   4935
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton btnSubmit 
      Caption         =   "Submit"
      Height          =   495
      Left            =   1800
      TabIndex        =   2
      Top             =   1200
      Width           =   1455
   End
   Begin VB.TextBox txtName 
      Height          =   495
      Left            =   1440
      TabIndex        =   1
      Top             =   360
      Width           =   3255
   End
   Begin VB.Label lblName 
      Caption         =   "Name"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   240
      TabIndex        =   0
      Top             =   480
      Width           =   975
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

As it can be seen from the above generated code that all the control informations maintain a particular pattern. They enclose themselves within the Begin and End statement. As said above that the Form occupies the top of the hierarchy among the controls- so all controls embed themselves within the Form's Begin and End statement.

Stage 2: Data Filtering

Data filtering is the process where the relevant informations are cropped from the raw VB Form (.frm) file. The cropping occurs as per a particular pattern. This stage is the heart of VJHandShaker. Data Filtering proceeds as per the following algorithm.

Algorithm for Data Filtering:

Step 1: Read the file content till the End-Of-file has reached.
Step 2: Identify the root element where the root element begins with Begin VB.Form 
Step 3: Pick out the Form Name and store in memory
Step 4: Pick out other Form informations and store in memory
Step 5: If the Form has no child, go to step 8
Step 6: If the Form has sub-elements, identify them with their respective structures. A typical sub-element structure is 
		Begin VB.Control <Control Name>
				Property Name1 = Property Value
				Property Name2 = Property Value
				. . . . . . . . . . . . . . . . . . . . . . . . . . . .
				 . . . . . . . . . . . . . . . . . . . . . . . . . . . .
				Property Name (n) = Property Value
		End
Loop through the "Begin" statement of the sub-elements till the "End" statements has encounter and pick out the relevant informations and store in memory. Continue this process until the root element's (i.e. FORM) "End" statement has encountered. Then go to step 8.
Step 7: If the control has nested controls embedded within them, repeat step 6 until all the sub-elements and the root element's (i.e. FORM) "End" statement are processed. Then go to step 8.
Step 8: Send the informations to the Data Transformation stage

Stage 3: Data Transformation

VB and Java layout are different. It means the coordinate position of a control in VB doesn't hold the same in Java. Hence a transformation is needed. It is the process by which the control in both the applications will have the same appearance as far as User Interface is concern. This phase takes the input from Stage 2 and generates the output as a .java file.

The Data Transformation stage was built on a trial and error basis. The coordinate positions of the controls are captured in stage 2 by applying the above algorithm and there are divided by 14 for an almost precise look and feel of the controls.

Stage 4: Output Data (.java file)

This is the last step of the converter. It produces a .java file for each corresponding .frm file. Since Sun Micro System's convention of generating a .java file is that the file name (i.e. the .java file) and the class name should be same, VJHandShaker1.0 takes care of that too.

Section B: Working Process Of VJHandShaker1.0-Detailed Example

In this section a detailed view of the working of the VJHandShaker is presented.The interface of VJHandshaker is presented below.

The "Locate Project Folder" asks the user to choose the folder where .frm files are located. Once the user does that, the software will list the VB Form files(.frm(s)) in the "List Of VB Form Files" List Box as shown below

The List Box control will list the Filenames, their sizes in bytes, Creation Time and Last Access Time.For converting the VB Forms (.frm) to Java (.java) compatible, the user must click on the "Folder to Save Java Files" button which on the other hand will open Folder Browser Dialog Box. The user can either create a new folder for saving the .java files or can choose an existing folder for the same. The below figure will illustrate this.

Clicking on the "OK" button of the Folder Browser Dialog Box will initiate the process of conversion. The converted files will be list in the "List Of Java Files" List Box. The total conversion time will be highlighted in the top right corner beside the "Processing Time" label in milliseconds. A progress bar will indicate the actual conversion progress. This is shown below

For a detailed walk through of VJHandShaker, first of all we will design a Form in VB6.0.

Working Of Design1

The above design is only a blank VB Form devoid of any control. The code generated by the VB editor for the above design is as follows

 VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   3090
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   3090
   ScaleWidth      =   4680
   StartUpPosition =   3  'Windows Default
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

The corresponding .java file generated by VJHandShaker is presented below

The code generated by the software is as under

import javax.swing.*;
import java.awt.*;
public class Form1 extends JFrame
{
 	 public Form1()
 	 {
		 super("Form1");
 		 Container con = getContentPane();
 		 con.setLayout(null);
 		 setSize(334,220);
 		 setResizable(true);
 		 setVisible(true);
	}
	public static void main(String args[])
	{
	              Form1 app = new Form1();
                            app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 	} 
 }

Working Of Design2

This is a more sophisticated design. It depicts a Registration Form.The corresponding .java design produced by VBHandShaker1.0 is as under

The corresponding code generated is given below

import javax.swing.*;
import java.awt.*;
public class frmRegistration extends JFrame
{
 	 public frmRegistration()
 	 {
		super("RegistrationForm");
 		 Container con = getContentPane();
 		 con.setLayout(null);
 		 JButton Cancel = new JButton("Cancel");
 		 Cancel.setBounds(402,394,95,35);
 		 con.add(Cancel);
 		 JButton btnSubmit = new JButton("Submit");
 		 btnSubmit.setBounds(300,394,95,35);
 		 con.add(btnSubmit);
 		 JComboBox cmbNation = new JComboBox();
 		 cmbNation.setBounds(420,300,223,22);
 		 con.add(cmbNation);
 		 //  OR 
 		 //Choice cmbNation = new Choice();
 		 //cmbNation.setBounds(420,300,223,22);
 		 // con.add(cmbNation);
 		 JTextField txtEmail = new JTextField();
 		 txtEmail.setBounds(420,257,223,26);
 		 con.add(txtEmail);
 		 JTextField txtPhone = new JTextField();
 		 txtPhone.setBounds(420,214,223,26);
 		 con.add(txtPhone);
 		 JTextField txtFatherName = new JTextField();
 		 txtFatherName.setBounds(420,68,181,26);
 		 con.add(txtFatherName);
 		 JTextField txtAge = new JTextField();
 		 txtAge.setBounds(77,120,69,26);
 		 con.add(txtAge);
 		 JRadioButton opMale = new JRadioButton("Male");
 		 opMale.setBounds(420,111,52,26);
 		 con.add(opMale);
 		 JRadioButton opFemale = new JRadioButton("Female");
 		 opFemale.setBounds(488,111,61,26);
 		 con.add(opFemale);
 		 JTextArea txtAddress = new JTextArea();
 		 txtAddress.setEditable(true);
 		 JScrollPane txtAddressSP = new JScrollPane( txtAddress,          
                                                 ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, 
                                                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
 		 txtAddressSP.setLocation(77,171);
 		 txtAddressSP.setSize(223,103);
 		 con.add(txtAddressSP);
 		 JCheckBox chkGame = new JCheckBox("Game");
 		 chkGame.setBounds(77,291,52,18);
 		 con.add(chkGame);
 		 JCheckBox chkReading = new JCheckBox("Reading");
 		 chkReading.setBounds(145,291,69,18);
 		 con.add(chkReading);
 		 JCheckBox chkFishing = new JCheckBox("Fishing");
 		 chkFishing.setBounds(231,291,61,26);
 		 con.add(chkFishing);
 		 JCheckBox chkQuize = new JCheckBox("Quize");
 		 chkQuize.setBounds(77,317,52,18);
 		 con.add(chkQuize);
 		 JCheckBox chkStamp = new JCheckBox("Stamp");
 		 chkStamp.setBounds(145,317,61,26);
 		 con.add(chkStamp);
 		 JCheckBox chkCoin = new JCheckBox("Coin");
 		 chkCoin.setBounds(231,317,61,26);
 		 con.add(chkCoin);
 		 JComboBox cmbDate = new JComboBox();
 		 cmbDate.setBounds(420,171,61,22);
 		 con.add(cmbDate);
 		 //  OR 
 		 //Choice cmbDate = new Choice();
 		 //cmbDate.setBounds(420,171,61,22);
 		 // con.add(cmbDate);
 		 JComboBox cmbMonth = new JComboBox();
 		 cmbMonth.setBounds(488,171,86,22);
 		 con.add(cmbMonth);
 		 //  OR 
 		 //Choice cmbMonth = new Choice();
 		 //cmbMonth.setBounds(488,171,86,22);
 		 // con.add(cmbMonth);
 		 JComboBox cmbYear = new JComboBox();
 		 cmbYear.setBounds(582,171,61,22);
 		 con.add(cmbYear);
 		 //  OR 
 		 //Choice cmbYear = new Choice();
 		 //cmbYear.setBounds(582,171,61,22);
 		 // con.add(cmbYear);
 		 JTextField txtName = new JTextField();
 		 txtName.setBounds(77,68,223,26);
 		 con.add(txtName);
 		 ImageIcon imgPhoto = new ImageIcon("blank.gif");
 		 JLabel lblimgPhoto = new JLabel(imgPhoto,JLabel.CENTER);
		 lblimgPhoto.setBounds(617,17,128,130);
 		 con.add(lblimgPhoto);
 		 JLabel lblNation = new JLabel("Nation :");
 		 lblNation.setBounds(334,300,61,18);
 		 con.add(lblNation);
 		 JLabel lblEmail = new JLabel("Emal :");
 		 lblEmail.setBounds(334,257,52,18);
 		 con.add(lblEmail);
 		 JLabel lblPrimaryPhone = new JLabel("Phone :");
 		 lblPrimaryPhone.setBounds(334,214,52,18);
 		 con.add(lblPrimaryPhone);
 		 JLabel lblFatherName = new JLabel("Father Name :");
 		 lblFatherName.setBounds(325,68,78,18);
 		 con.add(lblFatherName);
 		 JLabel lblAge = new JLabel("Age :");
 		 lblAge.setBounds(8,120,35,18);
 		 con.add(lblAge);
 		 JLabel lblSex = new JLabel("Sex :");
 		 lblSex.setBounds(334,120,35,18);
 		 con.add(lblSex);
 		 JLabel lblAdress = new JLabel("Address :");
 		 lblAdress.setBounds(8,171,52,26);
 		 con.add(lblAdress);
 		 JLabel lblHobbies = new JLabel("Hobbies :");
 		 lblHobbies.setBounds(8,291,52,18);
 		 con.add(lblHobbies);
 		 JLabel lblDob = new JLabel("DOB :");
 		 lblDob.setBounds(334,171,43,18);
 		 con.add(lblDob);
 		 JLabel lblName = new JLabel("Name :");
 		 lblName.setBounds(8,68,43,26);
 		 con.add(lblName);
 		 JLabel lblRegForm = new JLabel("Registration Form");
 		 lblRegForm.setBounds(300,17,103,18);
 		 con.add(lblRegForm);
 		 setSize(767,547);
 		 setResizable(true);
 		 setVisible(true);
	}
	public static void main(String args[])
	{
 		 frmRegistration app = new frmRegistration();
 		 app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 	} 
 }

Working Of Design3

The last but not the least design is about some more controls which the software has learnt about. This is presented in the below screen shot.

VJHandShaker gives the following output

Section C: Handshaking of Controls between VB Forms and JAVA

The following table presents a roster of controls that VJHandShaker1.0 has mapped so far

References

  1. http://msdn2.microsoft.com/en-us/library/aa241723.aspx
  2. Java 2:The Complete Reference, Third Edition (Patrick Naughton & Herbert Schildt)
  3. C#.Net fundas (Yashavant Kanetkar)
  4. Mastering Visual Basic 6 (Evangelos Petroutsos)

Conclusion

VJHandShaker1.0 is an attempt to make a quick java design interface from VB. However, it can also be used to convert the design interface of any legacy application built in VB to Java too. Also it reduces the design time of the java application.I hope, that, my readers will like the concept and will extend the software. Zipped files is attached herewith.Thanks for reading.

Page copy protected against web site content infringement by Copyscape

About the Author

Niladri.Biswas
Full Name: Niladri Biswas
Member Level: Platinum
Member Status: Member
Member Since: 10/25/2010 11:04:24 AM
Country: India
Best Regards, Niladri Biswas
http://www.dotnetfunda.com
Technical Lead at HCL Technologies

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)