# Can I create new class which is not a inner class but still with the ability to draw shape?

**URL:** <https://discourse.processing.org/t/can-i-create-new-class-which-is-not-a-inner-class-but-still-with-the-ability-to-draw-shape/39244>\
**Category:** Coding Questions\
**Created:** [October 13, 2022, 2:56pm UTC](https://discourse.processing.org/t/can-i-create-new-class-which-is-not-a-inner-class-but-still-with-the-ability-to-draw-shape/39244 "2022-10-13T14:56:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Malloc](https://avatars.discourse-cdn.com/v4/letter/m/45deac/32.png) [@Malloc](https://discourse.processing.org/u/Malloc)\
**Post date:** [October 13, 2022, 2:56pm UTC](https://discourse.processing.org/t/can-i-create-new-class-which-is-not-a-inner-class-but-still-with-the-ability-to-draw-shape/39244/1 "2022-10-13T14:56:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [October 13, 2022, 3:25pm UTC](https://discourse.processing.org/t/can-i-create-new-class-which-is-not-a-inner-class-but-still-with-the-ability-to-draw-shape/39244/2 "2022-10-13T15:25:34Z")

</div>

> [@Malloc](#):
>
> How can we split the new class from the one extends PApplet and still keep the ability to call its built-in methods?

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.

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [October 13, 2022, 4:41pm UTC](https://discourse.processing.org/t/can-i-create-new-class-which-is-not-a-inner-class-but-still-with-the-ability-to-draw-shape/39244/3 "2022-10-13T16:41:25Z")

</div>

> [@GoToLoop](#):
>
> Or you can create a “.java” file t

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

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

```auto
foo = new Foo(this);

```

and in draw something like this

```auto
foo.drawRect();

```

If I made a typo I am sure you can work it out.

PS welcome to the forum

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [October 13, 2022, 4:59pm UTC](https://discourse.processing.org/t/can-i-create-new-class-which-is-not-a-inner-class-but-still-with-the-ability-to-draw-shape/39244/4 "2022-10-13T16:59:31Z")

</div>

> [@quark](#):
>
> If you do the tab name must be the same name as the class (including case).

That’s a requirement only if there’s 1 class (or interface) declared as `public`.  
Otherwise the “.java” file can have a different name.

---

<div class="post-metadata">

**Author:** ![Malloc](https://avatars.discourse-cdn.com/v4/letter/m/45deac/32.png) [@Malloc](https://discourse.processing.org/u/Malloc)\
**Post date:** [October 14, 2022, 5:04am UTC](https://discourse.processing.org/t/can-i-create-new-class-which-is-not-a-inner-class-but-still-with-the-ability-to-draw-shape/39244/5 "2022-10-14T05:04:57Z")

</div>

Thanks, so we need keep PApplet reference where need the Processing API. 👌

---

<div class="post-metadata">

**Author:** ![Malloc](https://avatars.discourse-cdn.com/v4/letter/m/45deac/32.png) [@Malloc](https://discourse.processing.org/u/Malloc)\
**Post date:** [October 14, 2022, 5:07am UTC](https://discourse.processing.org/t/can-i-create-new-class-which-is-not-a-inner-class-but-still-with-the-ability-to-draw-shape/39244/6 "2022-10-14T05:07:56Z")

</div>

Thanks, I use Processing with vscode, this is the way I need.
