I need to execute a method, (a method which creates a file), when I exit my program, how would I do this?
Implement a WindowListener (or extend WindowAdapter), use the windowClosing (if errors in the process should prevent the window from closing or something like that) or windowClosed method.
Heres the link for the official Sun (Erm... Oracle) tutorial that tells you how to create a WindowListener and add that to your JFrame: http://download.oracle.com/javase/tutorial/uiswing/events/windowlistener.html