# Can't draw on main window, calling methods from a secondary window (PApplet, image())

**URL:** <https://discourse.processing.org/t/cant-draw-on-main-window-calling-methods-from-a-secondary-window-papplet-image/13889>\
**Category:** Coding Questions\
**Created:** [September 9, 2019, 6:33am UTC](https://discourse.processing.org/t/cant-draw-on-main-window-calling-methods-from-a-secondary-window-papplet-image/13889 "2019-09-09T06:33:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pvag](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/pvag/32/5934_2.png) [@Pvag](https://discourse.processing.org/u/Pvag)\
**Post date:** [September 9, 2019, 6:33am UTC](https://discourse.processing.org/t/cant-draw-on-main-window-calling-methods-from-a-secondary-window-papplet-image/13889/1 "2019-09-09T06:33:45Z")

</div>

Hello !

From the main processing sketch file, I am instantiating _objectA_ that defines _methodA_, which draws stuff on a PImage, that it then draws on the main window, using the image() function. This works as expected, whenever the method is called from another basic object (an object of a class that is not extending PApplet). I am also instantiating _objectB_, whose class extends PApplet, to control a secondary window. In _objectB_, I have a knob that I want to use to control the background color of the main window: whenever the user interacts with this knob, _methodA_ in _objectA_ is triggered by _objectB_ (of course, _objectB_ is holding a valid\*\* reference to _objectA_, set from the main sketch file). When _methodA_ is called from inside _objectB_, nothing is displayed on the main window by the image() function (which is called inside _methodA_), even if I have instantiated _objectA_ from the main sketch file. Why is that ? I would expect image() to be dependent on the object it is called from (i.e. _objectA_, and not _objectB_). Should I find a reference to the main window, instead, right from inside _objectB_ or _objectA_ and then do something like:

```auto
mainWindow.image(im, 0, 0);

```

instead of

```auto
image(im, 0, 0);

```

?

I hope this is somehow understandable. Thank you for stopping by, have a good day, folks 🌴😉

\*\*it can print correctly to the console

---

<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:** [September 9, 2019, 7:32am UTC](https://discourse.processing.org/t/cant-draw-on-main-window-calling-methods-from-a-secondary-window-papplet-image/13889/2 "2019-09-09T07:32:14Z")

</div>

The short answer is that it is not allowed by Java.

Each window has its own main event handling thread and any drawing to this window _must be done inside its own thread_,
