Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

Getting Started with Visual COBOL for Eclipse

Getting Started with Visual COBOL for Eclipse

Getting Started with Visual COBOL for Eclipse

Hello World using COBOL JVM

 

Summary:

This getting started tutorial shows how you can create a Java user interface and call a COBOL application to perform the backend processing. We’re using the Google Window Toolkit to design the user interface. The walkthrough will guide you through the process of setting this up.

Before creating your application, we need to add some new extensions to your Eclipse IDE.

 

Install Google Window Builder

Google Window Builder provides a UI designer within Eclipse that allows you to create graphical applications for Java using drag and drop.

 Help-> Install new software

Add the following URL for Eclipse 3.7 Window Builder support to the Work With field – you don’t need to click Add.

http://dl.google.com/eclipse/inst/d2wbpro/latest/3.7

Select all components and click next and then complete the installation.

 

 

 Once Eclipse has installed the software, restart with a fresh workspace

  

From the file -> new menu, choose other

 

 

Select Java Project, click next 

 

Name your project and click finish to create it

 

From File New Menu select other, type JDialog and click next. If JDialog isn’t available, check you have correctly installed Google Window Builder

 

 

Add these details and click OK



 Your screen should now look something like this


If you click the Design tab in the MainDialog.Java edit window the designer should open allowing you to paint a user interface

 

 In the components section of the palette, click the JButton

 And then click the dialog, you should now have a button on the main dialog window

 

Using the properties Window, you can change the button’s attributes. Change the text property.

 Now double click the button to generate an event handler.

 

The actionPerformed method gets called every time the button is invoked. We’re going to call a COBOL  from this method but before we do that, we need to create a COBOL project

 

From the File New Menu, select other and type COBOL JVM project and click next

 

Name the project and click finish

 

 

From the File new menu, click other and type COBOL JVM class and fill in these details, don’t forget the namespace

 

Change the name of the method-id instanceMethod to sayHelloWorld and add the following code to the method:

 

class-id com.mf.COBOLClass public. 

working-storage section.

method-id sayHelloWorld static.

local-storage section.

procedure division.

  invoke type javax.swing.JOptionPane::showMessageDialog(null, "Hello World")

  goback.

end method.

end class.

 

Save the source file which will cause Eclipse to build the application and check there are no errors.

Right-click the Java project and choose “properties”.

 

 

 From the next dialog, click Java Build path and the projects tab.

 Here you can add a reference to the COBOL project.

 

 The Java application can now invoke the COBOL method. Add the following code:

 

JButton btnNewButton = new JButton("Click Me");

btnNewButton.addActionListener(new ActionListener() {

 

public void actionPerformed(ActionEvent arg0) {

com.mf.COBOLClass.sayHelloWorld();

 }


Save the source file and check there are no errors.

 

You can now run the application.

 

Make sure the Java project is selected and then from the toolbar, click the debug icon

 


 

 

 

 

 

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Version history
Revision #:
1 of 1
Last update:
‎2012-12-14 05:57
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.