PApplet, switching between multiple windows with key input

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

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;
    }
  }
}

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?

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;
  }
}
1 Like