50.2 Connecting to Object Interface via Java

When using Java code to connect to the Object Interface, you must create the appropriate file structure to be able to "build" your Java project. This requires some experience with creating a Java build environment.

To avoid the need to create an appropriate development environment, you can simply copy the full structure of the Object Interface Example project (described below) to another location on your computer and network. With the same file structure, you will be able to create Java source code in the folder ../src/com/treeage/treeagepro/tutorials/, placing your new source files alongside the example file UseObjectInterface.java.

Make sure you do not make changes directly in the Object Interface Example project as this project could be overwritten when new software is released.

If a new version of the Object Interface Example project is released, copy the appropriate files to your project. Be sure not to overwrite any of your own source code.

Sample Java code

Sample Java code is provided in the Object Interface Example project installed with your software. You can access the appropriate file through the Files View (see below).

The UseObjectInterface.java source file contains sample Java code that opens, edits and analyzes sample trees. You can use this file as a starting point for creating your own Java source code.

If you choose to create your own source code using this example, be sure to save the file using a different filename. In fact, we recommend copying the entire project to a separate location. Otherwise, your source could be overwritten if an updated version of the example code is released.

This section will introduce you to the sample Java code. However, the Java code itself contains comments that serve as the primary documentation.

The UseObjectInterface.java file contains a Java class of the same name. That class runs as a Java application based on the existence of the method main. The main method instantiates the class, which immediately calls the class constructor UseObjectInterface, which contains the main processing steps. Additional methods provide the details on opening, modifying and analyzing trees.

To execute the code, right-click in the Java code document and select Run As > Java Application from the menu.

As the sample code executes, it writes a status output to the Java output Console. See below.