To use Processing in Eclipse, start by creating a new Java project. Then, select File > Import
and then choose General > File System
to locate the core.jar
file. It can be found in PATH_TO_PROCESSING/core/library/
for Windows or /Applications/Processing 3.app/Contents/Java/core/library/
for Mac. Once this is completed, right-click on core.jar
and add it to the build path.
The boilerplate for using Processing in Eclipse is as follows:
import processing.core.PApplet;
public class UsingProcessing extends PApplet {
// The argument passed to main must match the class name
public static void main(String[] args) {
PApplet.main("UsingProcessing");
}
// method used only for setting the size of the window
public void settings(){
}
// identical use to setup in Processing IDE except for size()
public void setup(){
}
// identical use to draw in Prcessing IDE
public void draw(){
}
}
The settings()
method is used to set the size of the window. For example, to create a 400x400 window, write the following:
public void settings(){
size(400,400);
}
Everything else as outlined in the Hello World documentation in terms of the use of setup()
and draw()
applies here.
As a final example, here is the code from the Drawing a Line example were it to be written in Eclipse:
import processing.core.PApplet;
public class UsingProcessing extends PApplet {
// The argument passed to main must match the class name
public static void main(String[] args) {
PApplet.main("UsingProcessing");
}
// method for setting the size of the window
public void settings(){
size(500, 500);
}
// identical use to setup in Processing IDE except for size()
public void setup(){
background(0);
stroke(255);
strokeWeight(10);
}
// identical use to draw in Prcessing IDE
public void draw(){
line(0, 0, 500, 500);
}
}