Create your own Processing Applet

An Eclipse project needs to do four things in order to utilize the Processing library:
  1. Add the processing-<linux/windows/osx>.jar file to the project's build path
  2. Inherit from PApplet
  3. Define the methods setup() and draw()
  4. Pass startup arguments to the Processing library
These steps were performed for you in the Lab7 base project, but they are listed here for reference if you decide to use Processing on your own.

A : Adding processing.jar

A jar file is a Java Archive. There are different types of jar files; some are self-executing and some just act as a container for classes of some library. It is equivalent to zip file specific to Java and is the typical format for Java distribution.

Choose the link corresponding to the operating system you are running.
If you are using a lab machine, choose the first link (processing-linux.jar).
Save the file to a place you can remember (i.e. your Downloads folder).
(Note that the Windows version has not been tested on Windows 7, but should work if Java is installed)

This .jar file contains the set of classes that make up the Processing library.
In order to use them in Eclipse, we must import the .jar file into our workspace.

The process is identical to importing .java files:

Once we've added the .jar file to the project, we need to add it to the project's classpath.
The classpath tells Java where to look for any methods we call outside of our package.

Currently, our project folder should look like this:



To add the Processing .jar to your classpath:

B : Inheriting from PApplet

PApplet is a class that defines (almost) every method in the Processing API.

This class is one of several defined in the .jar file we downloaded.
Our main class, Lab7, is written to inherit from PApplet.

Any class that will use Processing's functions needs to override the methods defined in PApplet.
There are various ways to do this; however, it is easiest to have your main class extend PApplet.
In Lab7.java, for instance, the declaration for the class is public class Lab7 extends PApplet { ... }


C : setup() and draw()

Every Processing application has the methods setup() and draw().

D : Startup arguments

Processing was originally designed to be run in web browsers. To use it in standalone programs, we have to pass arguments to the library indicating this.

Typically, we place this line at the bottom of main:
where 'package.Class' is replaced with the name of the package and class where main is defined.

This creates an array of Strings that are arguments to the Processing library. There are many different arguments we can pass.

Another common set is:
This makes your program draw to a full-screen window.