Create your own Processing Applet
An Eclipse project needs to do four things in order to utilize the Processing library:
- Add the processing-<linux/windows/osx>.jar file to the project's build path
- Inherit from PApplet
- Define the methods setup() and draw()
- 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:
-
Right click on Lab7 in the Package Explorer and choose Import-->Filesystem
-
Browse to the directory where you saved the .jar file, check the box next to
processing-<linux/windows/osx>.jar, and click Finish
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:
- Right click on the .jar file in the Package Explorer
-
Go to Build Path-->Add to Build Path
- Your project folder should now have a Referenced Libraries subfolder with your .jar file one level below.
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().
- public void setup()
- Initializes a window to a given size, and sets a background color
- Sets any other options that won't change.
- This method is called one time, when initializing our program's window.
- public void draw()
- Each time this method is called, the contents of the entire window are redrawn.
- draw() is called repeatedly by Processing to create animation.
- Each call draws to the window as if it had been wiped clean.
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:
- PApplet.main (new String[]{"package.Class"});
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:
- PApplet.main (new String[]{"--present", "package.Class"})
This makes your program draw to a full-screen window.