PageRenderTime 9ms CodeModel.GetById 1ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/trunk/Examples/java/callback/runme.java

#
Java | 56 lines | 42 code | 11 blank | 3 comment | 0 complexity | 9a923dabd17be28aa611276e0482a82e MD5 | raw file
 1public 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
12  public static void main(String[] args)
13  {
14    System.out.println("Adding and calling a normal C++ callback");
15    System.out.println("----------------------------------------");
16
17    Caller              caller = new Caller();
18    Callback            callback = new Callback();
19    
20    caller.setCallback(callback);
21    caller.call();
22    caller.delCallback();
23
24    callback = new JavaCallback();
25
26    System.out.println();
27    System.out.println("Adding and calling a Java callback");
28    System.out.println("------------------------------------");
29
30    caller.setCallback(callback);
31    caller.call();
32    caller.delCallback();
33
34    // Test that a double delete does not occur as the object has already been deleted from the C++ layer.
35    // Note that the garbage collector can also call the delete() method via the finalizer (callback.finalize())
36    // at any point after here.
37    callback.delete();
38
39    System.out.println();
40    System.out.println("java exit");
41  }
42}
43
44class JavaCallback extends Callback
45{
46  public JavaCallback()
47  {
48    super();
49  }
50
51  public void run()
52  {
53    System.out.println("JavaCallback.run()");
54  }
55}
56