# Opening and closing extra window

**URL:** <https://discourse.processing.org/t/opening-and-closing-extra-window/26021>\
**Category:** Coding Questions\
**Created:** [December 7, 2020, 8:57pm UTC](https://discourse.processing.org/t/opening-and-closing-extra-window/26021 "2020-12-07T20:57:25Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [December 7, 2020, 8:57pm UTC](https://discourse.processing.org/t/opening-and-closing-extra-window/26021/1 "2020-12-07T20:57:26Z")

</div>

This is my second time asking. The previous time I was unclear about what I wanted, however, it was still useful, so I don’t want to delete it.

I want to be able to create an extra window, within the same sketch and make it fully interactive with the previous one (the first one will be the command center, that will order things to appear or the second). The window should be resizable (surface.setResizable(true)) and if possible able to appear and disappear with a single function (for a different project I am working on).

If you can please give me a bare-bones code so I can improve it (I have both sides programmed, I just need to add the second window for it to be finished)

I have tried a few times but still failed. I hope you can help me with that.

Thanks

---

<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 7, 2020, 9:15pm UTC](https://discourse.processing.org/t/opening-and-closing-extra-window/26021/2 "2020-12-07T21:15:28Z")

</div>

[Forum.Processing.org/two/discussion/16457/size-method-for-intial-window-not-working-when-more-windows-are-are-added#Item\_1](http://Forum.Processing.org/two/discussion/16457/size-method-for-intial-window-not-working-when-more-windows-are-are-added#Item_1)

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [December 7, 2020, 9:49pm UTC](https://discourse.processing.org/t/opening-and-closing-extra-window/26021/3 "2020-12-07T21:49:36Z")

</div>

but why do you need extra sketches if you have everything here ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/0/04ce3d259e536a657ed9bbbf7f7eabb0fe5ca991.png) ?

---

<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 7, 2020, 9:56pm UTC](https://discourse.processing.org/t/opening-and-closing-extra-window/26021/4 "2020-12-07T21:56:52Z")

</div>

That link is for a demo that contains 1 main sketch which creates 2 extra sketches.

Each sketch is a PApplet subclass which is ignited by **runSketch()**.

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [December 8, 2020, 10:01am UTC](https://discourse.processing.org/t/opening-and-closing-extra-window/26021/5 "2020-12-08T10:01:02Z")

</div>

but can they communicate with eachother?  
Like setting variables that the other window uses?  
But if it ignites another sketch why do you need the

```auto
static class ThirdApple...
     void settings() {
         size(400,400)
     }
     void draw() {

     }

```

if the other skectch must include it anyways

---

<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 8, 2020, 10:57am UTC](https://discourse.processing.org/t/opening-and-closing-extra-window/26021/6 "2020-12-08T10:57:15Z")

</div>

> [@CodeMasterX](#):
>
> But can they communicate with each other?

Yes, via their respective fields _sa_ & _ta_:

```auto
final SecondApplet sa = new SecondApplet();
final ThirdApplet ta = new ThirdApplet();

```

However b/c Processing isn’t threaded-safe we can’t directly call “drawing”-type methods outside their own PApplet.

> [@CodeMasterX](#):
>
> But if it ignites another sketch why do you need the…

Methods **settings()** & **setup()** are PApplet initializer callback methods.

That’s how a PApplet subclass works, via its callback methods.

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [December 8, 2020, 12:31pm UTC](https://discourse.processing.org/t/opening-and-closing-extra-window/26021/7 "2020-12-08T12:31:37Z")

</div>

but do settings & setup functions have to be the same as in the original sketch?

---

<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 8, 2020, 12:37pm UTC](https://discourse.processing.org/t/opening-and-closing-extra-window/26021/8 "2020-12-08T12:37:12Z")

</div>

- They do whatever we put inside them!
- Each PApplet has its own canvas, threads and callbacks.
- That link is just a very simple & lazy sketch example demoing 1 main PApplet + 2 extra PApplet instances.
