java - Unable to detect when user closes (Xs) JFrame -


this question has answer here:

for moderators: please see comments of answer: stackoverflow.com/a/16388697/1574975

i'm trying detect when user done using client program gui when close jframe example xing it, can close socket connections.

but i'm unable make happen when user closes jframe. informed need use windowlistener jframe doesn't seem work. class extends jframe , here part of constructor setting jframe:

        this.setcontentpane(pane);         this.setdefaultcloseoperation(jframe.exit_on_close);         this.pack();         this.setvisible(true);         final jframe thisframe = this;         thisframe.addwindowlistener(new windowadapter() {              @override             public void windowclosed(windowevent e) {                 system.out.println("user has closed window");             }         });     } 

the println inside doesn't printed why think doesn't work. doing right or need additional?

windowclosed won't called because jvm has been closed in response setdefaultcloseoperation been set jframe.exit_on_close.

use windowclosing instead or change defaultcloseoperation


Comments