# How do you detect / stop someone from closing the sketch?

**URL:** https://discourse.processing.org/t/how-do-you-detect-stop-someone-from-closing-the-sketch/26864
**Category:** Coding Questions
**Created:** [January 7, 2021, 9:27pm UTC](https://discourse.processing.org/t/how-do-you-detect-stop-someone-from-closing-the-sketch/26864 "2021-01-07T21:27:28Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![what42](https://avatars.discourse-cdn.com/v4/letter/w/8491ac/32.png) [@what42](https://discourse.processing.org/u/what42)
#### Post date: [January 7, 2021, 9:27pm UTC](https://discourse.processing.org/t/how-do-you-detect-stop-someone-from-closing-the-sketch/26864/1 "2021-01-07T21:27:28Z")

</div>

I want to have some code run before the sketch is closed, but I don’t know how to detect when the window itself has been closed by clicking its x. I’d also be okay with making the window borderless, but I can’t find a way to do that either. If nothing else works, I could just have it always be fullscreened, but I’d like to have it be windowed too. If anyone knows how to detect closing / make it borderless, please let me know.

Edit: hold on, I think I might have it

---

<div class="post-metadata">

### Author: ![micycle](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micycle/32/201_2.png) [@micycle](https://discourse.processing.org/u/micycle)
#### Post date: [January 7, 2021, 10:09pm UTC](https://discourse.processing.org/t/how-do-you-detect-stop-someone-from-closing-the-sketch/26864/2 "2021-01-07T22:09:24Z")

</div>

> [@Save when app close, exit() ... stop()](https://discourse.processing.org/t/save-when-app-close-exit-stop/25754/7):
>
> Interesting. Try this then: public void dispose() { println("Print this when sketch is closed."); super.dispose(); }

---

<div class="post-metadata">

### Author: ![what42](https://avatars.discourse-cdn.com/v4/letter/w/8491ac/32.png) [@what42](https://discourse.processing.org/u/what42)
#### Post date: [January 7, 2021, 10:11pm UTC](https://discourse.processing.org/t/how-do-you-detect-stop-someone-from-closing-the-sketch/26864/3 "2021-01-07T22:11:35Z")

</div>

> [@Save when app close, exit() ... stop()](https://discourse.processing.org/t/save-when-app-close-exit-stop/25754/7):
>
> ```auto
> public void dispose() {
> println("Print this when sketch is closed.");
> super.dispose();
> }
> 
> ```

That worked! Thank you so much!
