Calling the Java class from PowerBuilder
In the open event of a window, create a Java VM:
// instance variable: javavm i_jvm
string properties[]
i_jvm = create javavm
string classpath
i_jvm.createjavavm(classpath, properties)
In the clicked event of a button on the window, create an instance of the Converter class using the CreateJavaObject method of the JavaVM instance, and call the conv method on the Converter class:
converter conv
double yen
i_jvm.createjavaobject(conv, "Converter", "converter")
yen = conv.dollarToYen(100.0)
messagebox("Yen", string(yen))
When the CreateJavaObject method is called in PowerScript, the PBVM calls the corresponding C++ method in the extension. The C++ method creates a Java Converter object through JNI. If it is successful, the method creates an instance of the PowerBuilder Converter proxy and a JavaMarshaler object, and associates the JavaMarshaler object with the PowerBuilder proxy.
When conv.dollarToYen(100.0)
is
called in PowerScript, the PowerBuilder VM calls the InvokeRemoteMethod method
on the JavaMarshaler object, which delegates the call to the Java
Converter object though JNI and returns the result to PowerBuilder.