Fuzzyzilla
Fuzzyzilla

Reputation: 356

Issue With Multiple Windows In Processing

I have a very simple sketch that opens multiple windows, like so:

void setup(){
  size(100,100);
  noLoop();
}
void keyPressed(){
  String[] args={"Secondary window!"};
  SecondWindow window=new SecondWindow();
  PApplet.runSketch(args, window);
}

class SecondWindow extends PApplet{
  void setup(){
    size(100,100);
    background(~0);
    noLoop();
  }
  void keyPressed(){
    exit();
  }
}

However, there is an issue: How can I close just child window? Pressing the [X] on the child window closes both the parent and child sketch, and the function exit() does the same.

Is there a method to close only the child applet? The PApplet documentation does not list any methods that seem to do this!

Thank you!

Upvotes: 0

Views: 327

Answers (1)

Kevin Workman
Kevin Workman

Reputation: 42176

The surface variable gives you access to the underlying window. You can call surface.setVisble(false) to hide the window.

void setup(){
  size(100,100);
  noLoop();
}
void keyPressed(){
  String[] args={"Secondary window!"};
  SecondWindow window=new SecondWindow();
  PApplet.runSketch(args, window);
}

class SecondWindow extends PApplet{
  void setup(){
    size(100,100);
    background(~0);
    noLoop();
  }
  void keyPressed(){
    surface.setVisible(false);
  }
}

Upvotes: 1

Related Questions