User Tools

Site Tools


Processing Tutorial

Part 6: Including Outside Code

6.1: Import

To import any of the libraries in Processing's Libraries folder, go to the Sketch → Import Library menu.

You can include any other libraries in you system's PATH by using the standard “import” statement. For example:

import java.util.ArrayList;  // get access to the ArrayList class
ArrayList dots = new ArrayList();  // create an ArrayList object

// put pixel values from first row of display window into dots
for (int i = 0; i < 100; i++) {
   Integer dot = new Integer(pixels[i]);
   dots.add((Object) dot);
6.2: Tabs and the Code Folder

You can use files without importing them by putting them in your sketch's “Code” folder.

Another means of including outside files is to use “tabs”. By choosing Sketch→Add File you can load an existing file into a new tab in the current project. Tabs can hold Java files or Pde files, and these can be mixed (however, files written in Basic and Continuous modes cannot be mixed). The new code will be copied to your sketch directory so that it will be automatically included (you can achieve the same result by simply copying the files into the directory yourself). You can also create a tab for a new file using the pull down menu on the right side of the tab bar, for adding new code.

Behind the scenes, Pde files in tabs are converted to inner classes of one big class (a subclass of PApplet) generated by Processing. This is an advanced mode - there are issues with regard to communicating information back and forth. See the Processing Environment on the Processing website for more on this feature.

Prev: Part 5- Running Programs | Next: Part 7- A few useful global variables

part_6-_including_outside_code.txt · Last modified: 2009/09/02 14:25 by scarl