If we create many class with different function, but all need to draw their shapes. How can we split the new class from the one extends PApplet and still keep the ability to call it’s build in methods?
It’s too long to manage the class if they are all inner classes.
Inner classes aren’t subclasses that extend their outer class but merely just another member of it, along w/ its fields, methods & constructors.
B/c of that an inner class has access to any other member of its outer class regardless its access level being private or anything else.
Now if you wanna make your class not depend on PApplet inside a “.pde” file you can declare it as static.
Or you can create a “.java” file tab which would make your class 100% self-standing.
Regardless which way you pick you’ll need to request (or find out) a PApplet reference in order to access the Processing API inside your non-inner class.
If you do the tab name must be the same name as the class (including case). If you want to access Procesing’s methods you need to add an import to this tab and a reference to the PApplet (sketch) object
If I remember correctly to make a class called Foo create a tab called Foo,java and inside
Foo,java
import processing.core.*;
public class Foo{
PApplet p; // reference to the sketch
public Foo(Papplet papp){
this.p = papp;
}
drawRect(){
p.fill(255,0,0);
p.noStroke();
p.rect(20,20,200,50);
}
}
In you main sketch tab you can create a Foo object like this