To initialize an instance of the newly created wrapper object (based on the IDL object described in Sample IDL Object) using createObject, complete the following steps:

  1. Create a Java file named idlexfoo_example.java and save it in the Export directory created by the Assistant. Include the following lines of code in the file:

    // Reference the default package generated by the Assistant.
    package idlexfoo;
     
    // Reference the javaidl export bridge classes.
    import com.idl.javaidl.*;
     
    //Create main class, subclassing from object created by
    //Bridge Assistant. You can either subclass or create a
    //member variable of the object.
    public class idlexfoo_example extends idlexfoo implements JIDLOutputListener
    {
      //Create a variable referencing the exported object
      private idlexfoo fooObj;
       
      // Constructor.
      public idlexfoo_example()
          {
          >// Create the wrapper object
          fooObj = new idlexfoo();
           
          // Add output listener to access IDL output.
          fooObj.addIDLOutputListener(this);
           
          // Create the underlying IDL object and call
          // its ::Init method with parameters
          fooObj.createObject( );
          fooObj.executeString("PRINT, 'Created object'");
      }
       
      // Implement JIDLOutputListener
      public void IDLoutput(JIDLObjectI obj, String sMessage)
      {
          System.out.println("IDL: "+sMessage);
      }
       
      //Instantiate a member of the class.
      public static void main(String[] argv)
      {
          idlexfoo_example exampleObj = new idlexfoo_example();
      }
    }
  1. Open the Windows Command window by selecting Start > Run and enter
    cmd in the textbox.
  2. Use the cd command to change to the directory containing the idlexfoo directory.
  3. Reference the classpath of javaidlb.jar in the compile statement. Enter the following two commands (as single lines) to compile and execute the program, replacing <IDL_DIR> with the IDL installation directory:
    javac -classpath ".;IDL_DIR\resource\bridges\export\java\javaidlb.jar" idlexfoo\idlexfoo_example.java
    java -classpath ".;IDL_DIR\resource\bridges\export\java\javaidlb.jar" idlexfoo.idlexfoo_example

Tip: See Note on Running the Java Examples for information on non-Windows-style compile and execution commands.

After compiling and running the project, the output message will appear in the command window.