Terminate thread when frame closes
I made a JFrame which runs a thread, but when I close the frame it goes on running... I can't stop it unless I ctrl-alt-del.. How do I terminate it? I start it by calling start(), should I use run() instead?
(I'm scared to try since it f***s my pc up, so I would rather ask a knowledgeable person first) here's the related part of the code:
publicvoid run(){
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
while(true){
player.playerMove();
// repaint
repaint();
// end of while
try
{
Thread.sleep (speed);
}
catch (InterruptedException ex)
{
// do nothing
}
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
}
}
publicvoid start(){
Thread th =new Thread(this);
th.start();
}
Message was edited by:
nayon_7

