Multiple classes eclipse with processing

The class containing processings setup, settings, and draw methods should also contain your main method.
All other classes that are not processing sketches don’t need to extend PApplet.

If you want to have those classes use processing methods like “point(x, y)” for example, you will have to pass your main class (“Mouse” in this case)

import processing.core.PApplet;

public class Mouse extends PApplet {

    public static void main(String[] args) 
    {
		PApplet.main("Mouse");
	}

    ExampleClass myExampleClass; //Declare instance of your class
	public void setup() 
    {
		background(0);
	}
	public void settings() 
    {
		size(800, 800);
        myExampleClass = new ExampleClass(this); //Initialize instance by passing a reference to your main class 
                                                 //using the "this" keyword.
	}

	public void draw()
     {
		stroke(255);
		line(0, 0, mouseX, mouseY);
        myExampleClass.drawPoint(mouseX, mouseY);
	}
}

and then for example:

import processing.core.PApplet;

public class ExampleClass
{

    private PApplet parent;
    public ExampleClass(PApplet parent) // This will take your main class as an argument to use later on
    {
        this.parent = parent;
    }

    public void drawPoint(int x, int y)
    {
        parent.point(x, y); //Use processing methods like this in other classes.
    }
}

if you haven’t already, take a look at this:
https://processing.org/tutorials/eclipse/

2 Likes