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

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -