Terminate running threads on JFrame close
问题 How do I invoke extra operations when the user closes a JFrame window? I have to stop existing threads. As I understand it, setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); causes the frame to be closed and its thread to be stopped. Should threads be closed after JFrame.EXIT_ON_CLOSE ? Client: static boolean TERMINATE = false; public static void main(String[] args) { // some threads created while(true) { if(TERMINATE){ // do before frame closed break; } } } private static JPanel startGUI(){