I want to write a component that monitors other activities, but it’s listeners are to be removed when the component’s window is closed.
I don’t want to write this removal code many times, but want the component to handle it itself. (How) can i do it?
Thanks!
The
JFrameclass (which is the window) has aprocessWindowEventcallback that takes a single parameter calledWindoweventRegister this callback and if the parameter is of
WINDOW_CLOSEDyou can call the removal code inside.In the end the removal code is only written once (as you want it).
See the API for more details.
Update: See also this