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

[1570 byte] By [nayon_7a] at [2007-11-27 7:33:15]
# 1
yourFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
calvino_inda at 2007-7-12 19:13:40 > top of Java-index,Java Essentials,Java Programming...
# 2
Right, how could I forget that :D thanks
nayon_7a at 2007-7-12 19:13:40 > top of Java-index,Java Essentials,Java Programming...
# 3
[ edit ] nevermind [ /edit ]
gimbal2a at 2007-7-12 19:13:40 > top of Java-index,Java Essentials,Java Programming...
# 4
notice that the way you create threads is quite uniqueactually, for what you want to do, start method should not be overriden, you should create an instance of your class and call "start" on the instance ; that's all"new Thread(this)" is just... ODD! :p
calvino_inda at 2007-7-12 19:13:40 > top of Java-index,Java Essentials,Java Programming...