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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -