# PApplet, switching between multiple windows with key input

**URL:** <https://discourse.processing.org/t/papplet-switching-between-multiple-windows-with-key-input/40435>\
**Category:** Coding Questions\
**Created:** [January 4, 2023, 1:35am UTC](https://discourse.processing.org/t/papplet-switching-between-multiple-windows-with-key-input/40435 "2023-01-04T01:35:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mikey83](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mikey83/32/17956_2.png) [@Mikey83](https://discourse.processing.org/u/Mikey83)\
**Post date:** [January 4, 2023, 1:35am UTC](https://discourse.processing.org/t/papplet-switching-between-multiple-windows-with-key-input/40435/1 "2023-01-04T01:35:21Z")

</div>

Hi, im playing around with multiple windows with PApplet and just wondering if there’s any good resources available, cant seem to find any help on the things im trying to do like switch between windows being active by pressing the space bar or something, not sure if its even possible, if so can anyone help, here’s my code so far

```auto
PWindow win;

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

void setup() {
  win = new PWindow();
}

void draw() {
  
}

class PWindow extends PApplet {
  PWindow() {
    super();
    PApplet.runSketch(new String[]{this.getClass().getName()}, this);
  }

  int count = 3;
  int[][] grid = new int[count][count];
  float w;

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

  void setup() {
    surface.setTitle("Kernal");
    w = (float)width/count;
    noStroke();
  }

  void draw() {
    for (int y = 0; y < count; y++) {
      for (int x = 0; x < count; x++) {
        fill(grid[x][y] == 1 ? 255 : 0);
        rect(x*w, y*w, w, w);
      }
    }
  }

  void mousePressed() {
    if (mouseButton == LEFT) {
      int x = floor(mouseX/w);
      int y = floor(mouseY/w);
      grid[x][y] = grid[x][y] == 1 ? 0 : 1;
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Mikey83](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mikey83/32/17956_2.png) [@Mikey83](https://discourse.processing.org/u/Mikey83)\
**Post date:** [January 4, 2023, 1:45am UTC](https://discourse.processing.org/t/papplet-switching-between-multiple-windows-with-key-input/40435/2 "2023-01-04T01:45:45Z")

</div>

Solved myself lol, should have thought harder, just a matter of making the second window not visible, having a boolean in the class and keyPressed functions in the main and the class, if main is shown spacebar makes second window visible and if that second window is shown spacebar makes the boolean false, would still like to find some resources for how far PApplet can go?

```auto
PWindow win;

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

void setup() {
  win = new PWindow();
  surface.setVisible(true);
}

void draw() {
  
}

void keyPressed(){
  if (key == ' ') win.visible = !win.visible;
}

class PWindow extends PApplet {
  PWindow() {
    super();
    PApplet.runSketch(new String[]{this.getClass().getName()}, this);
  }

  int count = 3;
  int[][] grid = new int[count][count];
  float w;
  
  boolean visible = false;

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

  void setup() {
    surface.setTitle("Kernal");
    w = (float)width/count;
    noStroke();
  }

  void draw() {
    surface.setVisible(visible);
    for (int y = 0; y < count; y++) {
      for (int x = 0; x < count; x++) {
        fill(grid[x][y] == 1 ? 255 : 0);
        rect(x*w, y*w, w, w);
      }
    }
  }

  void mousePressed() {
    if (mouseButton == LEFT) {
      int x = floor(mouseX/w);
      int y = floor(mouseY/w);
      grid[x][y] = grid[x][y] == 1 ? 0 : 1;
    }
  }
  
  void keyPressed(){
    if (key == ' ') visible = !visible;
  }
}

```
