     /****************************************************************
      * Copyright (C) 1996 - 2000 Micro Focus International Ltd.     *
      * All Rights Reserved.                                         *
      ****************************************************************/

import com.microfocus.cobol.*;
import java.io.*;

public class arraydemo extends RuntimeSystem
{
	int myArray[][];
	
	static
	{
		/* Load the DLL containing the class */
/*		System.loadLibrary("arraydemo"); */

		/* Load the class */
		if (cobloadclass ("arraydemo", "arraydemo") != 0)
			System.out.println ("TODO: raise an exception");
	}

	/* Constructor. Initialise the array to pass to COBOL */
	public arraydemo()
	{
		myArray = new int[5][2];
		int i,j;
		for (i = 0; i < myArray.length; i++)
		{
			for (j = 0; j < myArray[i].length; j++)
				myArray[i][j] = i * 100 + j;
		}
	}
	
	/* Pass the array to COBOL, then display the modified contents */
	public int displayArray()
	{
		int retVal;		    
		int i,j;
		Object[] params = {myArray};
		try
		{
		   retVal = cobinvoke_int ("displayArray", params);
		}
		catch (Exception e)
		{
			retVal = 999;
			System.out.println (e.getMessage());
		}
		System.out.println("After the array has been passed to COBOL and each element has 50 added...");
		for (i = 0; i < myArray.length; i++)
		{
			for (j = 0; j < myArray[i].length; j++)
			{
			    System.out.print(i + "," + j + " : " + myArray[i][j]);
			    System.out.print(" ");
			}
			System.out.println(" ");
		}
		
		return retVal;
	}

	public int newArray()
	{
		int retVal = 0;		    
		try
		{
			cobinvoke_void ("newArray", null);
		}
		catch (Exception e)
		{
			retVal = 999;
			System.out.println (e.getMessage());
		}	    
		return retVal;
	}

}
