# How to access variables from PApplet (2nd window) in default window?

**URL:** https://discourse.processing.org/t/how-to-access-variables-from-papplet-2nd-window-in-default-window/26670
**Category:** Coding Questions
**Created:** [January 1, 2021, 4:23pm UTC](https://discourse.processing.org/t/how-to-access-variables-from-papplet-2nd-window-in-default-window/26670 "2021-01-01T16:23:52Z")
**Posts on this page:** 3
**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: [January 1, 2021, 4:23pm UTC](https://discourse.processing.org/t/how-to-access-variables-from-papplet-2nd-window-in-default-window/26670/1 "2021-01-01T16:23:52Z")

</div>

Hi!  
I recently saw someone’s code which allowed for 2 windows. I tried to adapt one of my programs to it but it didn’t work too well. I know I can just declare them at the beginning and be done with it, but is there a way to do it differently?

```auto
MultiWindows sketch2; 

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

void setup() {
  surface.setLocation(0, 0);
  surface.setTitle("Input window");
  sketch2 = new MultiWindows();
  
  
}

void draw() {
  background(255);
  stroke(255, 0, 0);
  println(txt);
}

class MultiWindows extends PApplet {
  String txt = "";
  MultiWindows() {
    super();
    PApplet.runSketch(new String[] {this.getClass().getSimpleName()}, this);
  }

  public void settings() {
    size(400, 400);
  }

  public void setup() {
    surface.setLocation(400, 0);
    surface.setTitle("Display window");
  }

  public void draw() {
    background(0);
    fill(255);
    text(txt,width/2,height/2);
  }
  public void keyPressed() {
    txt += key;
  }
}

```

---

<div class="post-metadata">

### Author: ![rbrauer](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@rbrauer](https://discourse.processing.org/u/rbrauer)
#### Post date: [January 2, 2021, 3:29am UTC](https://discourse.processing.org/t/how-to-access-variables-from-papplet-2nd-window-in-default-window/26670/2 "2021-01-02T03:29:15Z")

</div>

If you change “println(txt)” to “println(sketch2.txt)”, is that the behavior you were hoping to get?

---

<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: [January 2, 2021, 10:44am UTC](https://discourse.processing.org/t/how-to-access-variables-from-papplet-2nd-window-in-default-window/26670/3 "2021-01-02T10:44:21Z")

</div>

yes thank you. But can you do something like `sketch2.txt = "aaa"`?
