/trunk/Examples/java/callback/runme.java
Java | 56 lines | 42 code | 11 blank | 3 comment | 0 complexity | 9a923dabd17be28aa611276e0482a82e MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
- public class runme
- {
- static {
- try {
- System.loadLibrary("example");
- } catch (UnsatisfiedLinkError e) {
- System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
- System.exit(1);
- }
- }
- public static void main(String[] args)
- {
- System.out.println("Adding and calling a normal C++ callback");
- System.out.println("----------------------------------------");
- Caller caller = new Caller();
- Callback callback = new Callback();
-
- caller.setCallback(callback);
- caller.call();
- caller.delCallback();
- callback = new JavaCallback();
- System.out.println();
- System.out.println("Adding and calling a Java callback");
- System.out.println("------------------------------------");
- caller.setCallback(callback);
- caller.call();
- caller.delCallback();
- // Test that a double delete does not occur as the object has already been deleted from the C++ layer.
- // Note that the garbage collector can also call the delete() method via the finalizer (callback.finalize())
- // at any point after here.
- callback.delete();
- System.out.println();
- System.out.println("java exit");
- }
- }
- class JavaCallback extends Callback
- {
- public JavaCallback()
- {
- super();
- }
- public void run()
- {
- System.out.println("JavaCallback.run()");
- }
- }