Running a method when closing the program?

后端 未结 6 1215
無奈伤痛
無奈伤痛 2020-12-03 14:22

I need to execute a method, (a method which creates a file), when I exit my program, how would I do this?

6条回答
  •  抹茶落季
    2020-12-03 14:54

    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

提交回复
热议问题