Close second window and reopen example.

edited March 2017 in Share Your Work

I couldn't find any examples showing 2nd window close without exiting the first. Using exitActual() seems to do the trick. Any comments on this approach versus some alternative?

Note settings() is needed to correctly set the size(500, 500) of the first window. Also mousePressed() is used to reopen the window.

boolean frame2Exit;
String[] args = {"TwoFrameTest"};
SecondApplet sa;

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

void draw() {
  background(0);
  ellipse(50, 50, 10, 10);
}     

void mousePressed() {    
  if (frame2Exit)
  {
    frame2Start();
  }
}
void frame2Start() {
  sa = new SecondApplet();
  PApplet.runSketch(args, sa);
  frame2Exit = false;
}

public class SecondApplet extends PApplet {

  public void settings() {
    size(300, 300);
   }
  public void draw() {
    background(255);
    fill(0);
    ellipse(100, 50, 10, 10);
  }
  public void exitActual() {
    frame2Exit = true; 
  }
}
Sign In or Register to comment.