Run function on 'Close'

OK, so I’m trying to create an app where the user is prompted to save when the red ‘X’ a.k.a. the ‘Close’ button is clicked, but I can’t figure out how to run a function when that is clicked. I DO know how to prevent the program from automatically exiting when the ‘X’ is clicked, see below.


I’m using the JAVA2D renderer because I’m using the G4P library for my GUI. I’ve already got my save function written, so now I just have to call it in some sort of handler maybe?

I figured it out. :grinning: I just create a WindowListener Object.
https://docs.oracle.com/javase/9/docs/api/java/awt/event/WindowListener.html

3 Likes