java - Stop execution of a thread when a panel is removed from another panel -
i have panel (b) inside panel (a). panel (b) starts executing thread , updating own gui.
but there case user logs out of panel (b) , other panel ( panel (c) ) comes in place of (b), while thread keeps on executing.
i want interrupt (stop) thread when panel (b) no more visible ...any suggestions ?
one option add containerlistener panel a. check if panel b being removed , call "stopthread()" on panel b. i'd suggest creating interface "stopthread()" method (call interface c), create own panel class b such b extends panel implements c.
then in containerlistener.componentremoved method, test removed component:
if (component instanceof c) { c c = (c)component; c.stopthread(); }
you include startthread() , call when added using similar technique.
Comments
Post a Comment