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

Popular posts from this blog

c# - Unity IoC Lifetime per HttpRequest for UserStore -

Change the color of an oval at click in Java AWT -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -