# Closing One Window and Opening Another

**URL:** https://discourse.processing.org/t/closing-one-window-and-opening-another/28667
**Category:** Coding Questions
**Created:** [March 19, 2021, 9:53pm UTC](https://discourse.processing.org/t/closing-one-window-and-opening-another/28667 "2021-03-19T21:53:11Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Flamingo](https://avatars.discourse-cdn.com/v4/letter/f/919ad9/32.png) [@Flamingo](https://discourse.processing.org/u/Flamingo)
#### Post date: [March 19, 2021, 9:53pm UTC](https://discourse.processing.org/t/closing-one-window-and-opening-another/28667/1 "2021-03-19T21:53:11Z")

</div>

Hi there,  
I'm simply trying to run a program where I need to completely close one window/papplet and open a new one after an action has been made by the user (e.g. mousePressed). I need something that actually closes the class and opens the new one, not just some code like:  
window.getSurface().setVisible(false);  
Any help or guidance would be greatly appreciated!

---

<div class="post-metadata">

### Author: ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)
#### Post date: [March 20, 2021, 11:55pm UTC](https://discourse.processing.org/t/closing-one-window-and-opening-another/28667/2 "2021-03-20T23:55:16Z")

</div>

Hi,

> [@Flamingo](#):
>
> I need to completely close one window/papplet

When you run your code in Processing or export it as a standalone app, it is wrapped into a `PApplet` class with a `main` function that runs your code.

For example :

```auto
void setup() {
  size(500, 500);
}

void draw() {
  background(255);
  circle(mouseX, mouseY, 50);
}

```

Becomes :

```auto
import processing.core.PApplet;

public class test_app_export extends PApplet {
  public void setup() {}
  
  public void draw() {
    background(255);
    circle(this.mouseX, this.mouseY, 50.0F);
  }
  
  public void settings() {
    size(500, 500);
  }
  
  public static void main(String[] passedArgs) {
    String[] appletArgs = { "test_app_export" };
    if (passedArgs != null) {
      PApplet.main(concat(appletArgs, passedArgs));
    } else {
      PApplet.main(appletArgs);
    } 
  }
}

```

So closing the PApplet means closing your application 😉

One solution is to run another PApplet instance as described here :

- [Multiple windows with Processing 3](https://forum.processing.org/two/discussion/12272/multiple-windows-with-processing-3)

But when closing one window, it closes the others. Luckily for us, micycle provided a nice workaround :

> [@Prevent one Processing window from closing others](https://discourse.processing.org/t/prevent-one-processing-window-from-closing-others/13719/5):
>
> I’ve done some digging – inspired by @GoToLoop and @quark – and have found a solution. Closing sketches in P2D and JAVA2D renderer modes calls the PApplet instance’s exitActual() method, which contains the line System.exit(0) – a static method – which terminates the currently running Java virtual machine. Overriding exitActual() with nothing (i.e. preventing the call to System.exit(0)) prevents sketches from closing others, fixing the issue, but introduces another problem in the case of P2D s…

You can also stop the main PApplet instance and restart it but you’ll loose memory (you can always save it to a file) :

> <https://stackoverflow.com/questions/4159802/how-can-i-restart-a-java-application>
