# Multiple classes eclipse with processing

**URL:** <https://discourse.processing.org/t/multiple-classes-eclipse-with-processing/1142>\
**Category:** Beginners\
**Created:** [June 21, 2018, 8:06am UTC](https://discourse.processing.org/t/multiple-classes-eclipse-with-processing/1142 "2018-06-21T08:06:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![zejton](https://avatars.discourse-cdn.com/v4/letter/z/f0a364/32.png) [@zejton](https://discourse.processing.org/u/zejton)\
**Post date:** [June 21, 2018, 8:06am UTC](https://discourse.processing.org/t/multiple-classes-eclipse-with-processing/1142/1 "2018-06-21T08:06:26Z")

</div>

Hey!

So I am new to processing and would love some help with how to get **multiple classes working in eclipse with processing**

this is my code:

This is one class “mouse”:

```auto
import processing.core.PApplet;

public class Mouse extends PApplet {
	public void setup() {

		background(0);
	}

	public void settings() {
		size(800, 800);
	}

	public void draw() {
		stroke(255);
		line(0, 0, mouseX, mouseY);

	}
}

```

And this is the “main class”:

```auto
import processing.core.*;

public class Tester extends PApplet {

	public static void main(String[] args) {

		PApplet.main("Tester");

	}

}

```

I am not sure how to continue from here, it is not like processing where you can have everything in the “main” tab…

---

<div class="post-metadata">

**Author:** ![monkstone](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/monkstone/32/64_2.png) [@monkstone](https://discourse.processing.org/u/monkstone)\
**Post date:** [June 21, 2018, 10:31am UTC](https://discourse.processing.org/t/multiple-classes-eclipse-with-processing/1142/2 "2018-06-21T10:31:16Z")

</div>

You should start a bit further back, understanding how processing `pre-processes` a `*.pde` is very instructive:-

Processing caches it’s compiled java classes and a .java file every time you run a sketch, Apple will change where in the /var/folders/ directory this is. The fastest way to find the current location is to create a new sketch, don’t save it and press command+k which will open up the subdirectory of /var/folders/ where the sketch is temporarily stored.

Anyway should basically check that you understand what is going on, this will set you in good stead. Basically processing creates inner classes so that they can inherit methods etc from PApplet, you might not want to do that so, you need to know that you can access static methods using PApplet or instance methods on your instance of PApplet.

---

<div class="post-metadata">

**Author:** ![cumulus](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/cumulus/32/451_2.png) [@cumulus](https://discourse.processing.org/u/cumulus)\
**Post date:** [June 22, 2018, 10:06am UTC](https://discourse.processing.org/t/multiple-classes-eclipse-with-processing/1142/3 "2018-06-22T10:06:08Z")

</div>

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)

```auto
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:

```auto
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/](https://processing.org/tutorials/eclipse/)

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [June 22, 2018, 10:45am UTC](https://discourse.processing.org/t/multiple-classes-eclipse-with-processing/1142/4 "2018-06-22T10:45:25Z")

</div>

Are you looking to have multiple windows? Then I would use your first code in your first post with some modifications. However, your question is about working with _multiple classes_. It is possible but you need to be aware how to access the main sketch and **only** access it if you need to. For instance, if you have a class which is design to sort your data, then this class does not need to have access to the PApplet. Instead, you can pass data to the PApplet. You can do this by instantiating the object within the main sketch and then passing a reference of the PApplet to it as describe by @cumulus in the previous post. However, the most effective way is to return the data to the sketch so it can handle it. What strategy to implement depends on what you want to do and it is the fun part of the designing stage.

Kf

---

<div class="post-metadata">

**Author:** ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)\
**Post date:** [June 22, 2018, 8:26pm UTC](https://discourse.processing.org/t/multiple-classes-eclipse-with-processing/1142/5 "2018-06-22T20:26:09Z")

</div>

Like others have said, you should only have **one** class that extends `PApplet`.

Shameless self-promotion:

> **[Processing in Java](https://happycoding.io/tutorials/java/processing-in-java)**
>
> Learn how to use Processing as a Java library.

This guide walks you through using Processing as a Java library.

---

<div class="post-metadata">

**Author:** ![zejton](https://avatars.discourse-cdn.com/v4/letter/z/f0a364/32.png) [@zejton](https://discourse.processing.org/u/zejton)\
**Post date:** [June 26, 2018, 9:35am UTC](https://discourse.processing.org/t/multiple-classes-eclipse-with-processing/1142/6 "2018-06-26T09:35:54Z")

</div>

Thanks for the answers guys, I will try to learn more about processing. thanks for the guide aswell!

---

<div class="post-metadata">

**Author:** ![liuzc188](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/liuzc188/32/6596_2.png) [@liuzc188](https://discourse.processing.org/u/liuzc188)\
**Post date:** [August 13, 2019, 6:31am UTC](https://discourse.processing.org/t/multiple-classes-eclipse-with-processing/1142/7 "2019-08-13T06:31:31Z")

</div>

THX， help me a lot, very useful
