java - Run function on JFrame close -


void terminate() {} protected jframe frame = new jframe(); 

how can frame run terminate function when press close button?

edit: tried run this, reason doesn't print test (however, program closes). have idea problem?

frame.addwindowlistener(new windowadapter() {     public void windowclosing(windowevent e) {         system.out.println("test");         frame.dispose();     } }); 

you can use addwindowlistener:

frame.addwindowlistener(new windowadapter() {     public void windowclosing(windowevent e)     {         ... //call terminate         ...     } }); 

see void windowclosing(windowevent e) , class windowadapter too.


Comments

Popular posts from this blog

Winapi c++: DialogBox hangs when breaking a loop -

vb.net - Font adding using PDFsharp -

javascript - jQuery iScroll clickable list elements while retaining scroll? -