Java Object Initiation Without Parameters
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:
- Create a Java file named
idlexfoo_example.javaand save it in the Export directory created by the Assistant. Include the following lines of code in the file: - Open the Windows Command window by selecting Start → Run and enter
cmdin the textbox. - Use the
cdcommand to change to the directory containing theidlexfoodirectory. - Reference the classpath of
javaidlb.jarin 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:
// 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(); } }
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_exampleTip
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.