# Using PApplet whilst extending classes like PGraphics

**URL:** <https://discourse.processing.org/t/using-papplet-whilst-extending-classes-like-pgraphics/6942>\
**Category:** Coding Questions\
**Created:** [December 28, 2018, 4:55am UTC](https://discourse.processing.org/t/using-papplet-whilst-extending-classes-like-pgraphics/6942 "2018-12-28T04:55:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kluivert](https://avatars.discourse-cdn.com/v4/letter/k/dc4da7/32.png) [@Kluivert](https://discourse.processing.org/u/Kluivert)\
**Post date:** [December 28, 2018, 4:55am UTC](https://discourse.processing.org/t/using-papplet-whilst-extending-classes-like-pgraphics/6942/1 "2018-12-28T04:55:29Z")

</div>

Heya Everyone!  
I recently attempted to extend the PGraphics class specifically the PGraphicsJAVA2D class and referred to [GotoLoop’s Solution](https://discourse.processing.org/t/is-it-possible-to-extend-the-classes-pgraphics-pgraphics3d/1593/2?u=kluivert)  
But don’t understand the code as well which leaves me with anxiety.

---

<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:** [December 28, 2018, 9:18am UTC](https://discourse.processing.org/t/using-papplet-whilst-extending-classes-like-pgraphics/6942/2 "2018-12-28T09:18:19Z")

</div>

Then you should ask which exactly parts of the code you don’t understand. 😉

---

<div class="post-metadata">

**Author:** ![Kluivert](https://avatars.discourse-cdn.com/v4/letter/k/dc4da7/32.png) [@Kluivert](https://discourse.processing.org/u/Kluivert)\
**Post date:** [December 28, 2018, 12:32pm UTC](https://discourse.processing.org/t/using-papplet-whilst-extending-classes-like-pgraphics/6942/3 "2018-12-28T12:32:51Z")

</div>

the parts with the PApplet whilst defining the layer class.  
I haven’t found anything useful regarding the PApplet class, as far as i know its the base class for any Processing sketch.  
Also thanx for the reply, really appreciate it 🙂

---

<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:** [December 28, 2018, 1:01pm UTC](https://discourse.processing.org/t/using-papplet-whilst-extending-classes-like-pgraphics/6942/4 "2018-12-28T13:01:46Z")

</div>

> [@Kluivert](#):
>
> I haven’t found anything useful regarding the PApplet class, …

[Processing.GitHub.io/processing-javadocs/everything/processing/core/PApplet.html](http://Processing.GitHub.io/processing-javadocs/everything/processing/core/PApplet.html)

> [@Kluivert](#):
>
> The parts with the PApplet whilst defining the Layer class.

You mean from this very old sketch, right?

- [PShape inside a class, or extend PShape - Processing 2.x and 3.x Forum](http://Forum.Processing.org/two/discussion/16314/pshape-inside-a-class-or-extend-pshape#Item_4)

AFAIK, all PGraphics instances need to know which PApplet instance they should be bound to.

That’s why method Layer::**initialize()** calls PGraphics::**setParent()** within it:  
[Processing.GitHub.io/processing-javadocs/everything/processing/core/PGraphics.html#setParent-processing.core.PApplet-](http://Processing.GitHub.io/processing-javadocs/everything/processing/core/PGraphics.html#setParent-processing.core.PApplet-)

```java
public void initialize(int w, int h, PApplet p, String s) {
  setParent(p);
  setPrimary(false);
  setPath(s);
  setSize(w, h);
}

```

---

<div class="post-metadata">

**Author:** ![Kluivert](https://avatars.discourse-cdn.com/v4/letter/k/dc4da7/32.png) [@Kluivert](https://discourse.processing.org/u/Kluivert)\
**Post date:** [December 29, 2018, 4:51pm UTC](https://discourse.processing.org/t/using-papplet-whilst-extending-classes-like-pgraphics/6942/5 "2018-12-29T16:51:13Z")

</div>

Thank you so much for replying so actively : ) … I shall go through it and come back to clarify some extra things if necessary.  
Again Thanx!
