# Processing second PApplet window does not update when method is invoked

**URL:** <https://discourse.processing.org/t/processing-second-papplet-window-does-not-update-when-method-is-invoked/30392>\
**Category:** Processing\
**Created:** [May 31, 2021, 1:34pm UTC](https://discourse.processing.org/t/processing-second-papplet-window-does-not-update-when-method-is-invoked/30392 "2021-05-31T13:34:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gohag](https://avatars.discourse-cdn.com/v4/letter/g/a698b9/32.png) [@gohag](https://discourse.processing.org/u/gohag)\
**Post date:** [May 31, 2021, 1:34pm UTC](https://discourse.processing.org/t/processing-second-papplet-window-does-not-update-when-method-is-invoked/30392/1 "2021-05-31T13:34:17Z")

</div>

Hi!  
I have the following code which allows to have two windows, in the main window when the ‘k’ key is pressed, must call the function disegna() of Graph and add the text.

But it seems not to work properly, no draw update occurs.

Can you give me a hand?

 ![](https://i.stack.imgur.com/S6CWt.png)

```auto
int N = 500;
boolean flag = false;
Grafico graph = new Grafico(N, N);

void settings() {
  size(N, N);
}

void setup() {
  surface.setTitle("Grafico1");
  surface.setLocation(0, 0);

  String[] args = {
    "--location=" + (N*2) + ",0", 
    "Grafico2"
  };
  PApplet.runSketch(args, graph);
  grafico();
}

void grafico() {
  background(0);
  text("Main", 10, 20);
}

void keyPressed() {
  switch (key) {
  case 'k':
    graph.disegna();
    break;
  }
}

void draw() {
  if (!flag) {
    frame.setLocation(0, 0);
    flag = true;
  }
}

public class Grafico extends PApplet {
  private final int w, h;

  public Grafico(int w, int h) {
    this.w = w;
    this.h = h;
  }
  
  void settings () {
    size(w, h);
  }
  
  void setup() {
    ini();
  }

  void ini() {
    background(0);
    text("Second", 10, 20);
  }
  
  void disegna() {
     text("Hello!", 10, 50);
     println("Hello!");
  }
  
  void draw() {
  }
}

```

---

<div class="post-metadata">

**Author:** ![th75](https://avatars.discourse-cdn.com/v4/letter/t/ebca7d/32.png) [@th75](https://discourse.processing.org/u/th75)\
**Post date:** [June 1, 2021, 8:27pm UTC](https://discourse.processing.org/t/processing-second-papplet-window-does-not-update-when-method-is-invoked/30392/2 "2021-06-01T20:27:16Z")

</div>

hi,

```
graph.disegna(); works well (we see the hello! println)

```

but if you consider timing, there is a possible reason to not see it on second papplet window:

keyPressed is an event , occuring when key is released, so no reasons it occur during draw() loop and you can draw something only during draw

second, even if it occur during draw, not sure it is same timing for the second papplet drawing loop  
(and draw is empty so very very short )

because of that, i will not try to draw from one papplet inside the second one but use variable :

```auto
public class Grafico extends PApplet {
  private final int w, h;
  boolean disegna=false;
  public Grafico(int w, int h) {
    this.w = w;
    this.h = h;
  }

  void settings () {
    size(w, h);
  }

  void setup() {
    ini();
  }

  void ini() {
    background(0);

    text("Second", 10, 20);
  }

  void disegna() {
    disegna=true;
    println("Hello!");
  }

  void draw() {
    if (disegna) {     
      fill(255);
      text("Hello!", 10, 50);
    }
  }
}

```
