summaryrefslogtreecommitdiff
path: root/Examples/java/mpointer/main.java
blob: ab6cdf159a44f91b859e8c423327316496609817 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Example using pointers to member functions

public class main {
  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 argv[]) 
  {
      // Get the pointers

      SWIGTYPE_m_Shape__f_void__double area_pt = example.areapt();
      SWIGTYPE_m_Shape__f_void__double perim_pt = example.perimeterpt();

      System.out.println( "area_pt  =" + area_pt );
      System.out.println( "perim_pt = " + perim_pt );

      // Create some objects

      Circle c = new Circle(4);
      Square s = new Square(10);

      // Do some calculations

      System.out.println( "Circle area  = " + example.do_op(c,area_pt) );
      System.out.println( "Circle perim = " + example.do_op(c,perim_pt) );
      System.out.println( "Square area  = " + example.do_op(s,area_pt) );
      System.out.println( "Square perim = " + example.do_op(s,perim_pt) );

      System.out.println( "areavar      = " + example.getAreavar() );
      System.out.println( "perimetervar = " + example.getPerimetervar() );

      // Try the variables
      System.out.println( "Circle area  = " + example.do_op(c,example.getAreavar()) );
      System.out.println( "Circle perim = " + example.do_op(c,example.getPerimetervar()) );
      System.out.println( "Square area  = " + example.do_op(s,example.getAreavar()) );
      System.out.println( "Square perim = " + example.do_op(s,example.getPerimetervar()) );

      // Modify one of the variables
      example.setAreavar(perim_pt);

      System.out.println( "Circle perimeter = " + example.do_op(c,example.getAreavar()) );

      // Try the constants

      System.out.println( "example.AREAPT =" + example.AREAPT );
      System.out.println( "example.PERIMPT=" + example.PERIMPT );
      System.out.println( "example.NULLPT =" + example.NULLPT );

      System.out.println( "Circle area  = " + example.do_op(c,example.AREAPT) );
      System.out.println( "Circle perim = " + example.do_op(c,example.PERIMPT) );
      System.out.println( "Square area  = " + example.do_op(s,example.AREAPT) );
      System.out.println( "Square perim = " + example.do_op(s,example.PERIMPT) );

  }
}