Come posso richiamare operazioni extra quando l'utente chiude una finestra JFrame
? Devo interrompere i thread esistenti.Terminare i thread in esecuzione su JFrame close
Come ho capito, setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
causa la chiusura del frame e il suo thread da arrestare. I thread dovrebbero essere chiusi dopo lo JFrame.EXIT_ON_CLOSE
?
Cliente:
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(){
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel gui = new JPanel();
f.add(gui);
f.setSize(500,500);
f.setVisible(true);
return gui;
}
ho bisogno di chiudere le prese il filo del lavoro con. Qual è la migliore pratica per farlo?
Vedi anche [* §12.8. Uscita programma *] (http://docs.oracle.com/javase/specs/jls/se7/html/jls-12.html#jls-12.8). – trashgod