PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/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
  1. public class runme
  2. {
  3. static {
  4. try {
  5. System.loadLibrary("example");
  6. } catch (UnsatisfiedLinkError e) {
  7. 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);
  8. System.exit(1);
  9. }
  10. }
  11. public static void main(String[] args)
  12. {
  13. System.out.println("Adding and calling a normal C++ callback");
  14. System.out.println("----------------------------------------");
  15. Caller caller = new Caller();
  16. Callback callback = new Callback();
  17. caller.setCallback(callback);
  18. caller.call();
  19. caller.delCallback();
  20. callback = new JavaCallback();
  21. System.out.println();
  22. System.out.println("Adding and calling a Java callback");
  23. System.out.println("------------------------------------");
  24. caller.setCallback(callback);
  25. caller.call();
  26. caller.delCallback();
  27. // Test that a double delete does not occur as the object has already been deleted from the C++ layer.
  28. // Note that the garbage collector can also call the delete() method via the finalizer (callback.finalize())
  29. // at any point after here.
  30. callback.delete();
  31. System.out.println();
  32. System.out.println("java exit");
  33. }
  34. }
  35. class JavaCallback extends Callback
  36. {
  37. public JavaCallback()
  38. {
  39. super();
  40. }
  41. public void run()
  42. {
  43. System.out.println("JavaCallback.run()");
  44. }
  45. }