Please help me, i want to stop a thread when i press a button and its using actionperformed. But when i am implementing it it give me an exception.
Code is like this
MThread m = new MThread();
JButton b = new JButton("Stop");
public void actionPerformed()
if(e.getSource() == b)
1) You know that when you create a new Thread object, it is completely distinct from the previous Thread object, that calling methods on the one will have no effect on the other.
2) Also, the API will tell you that Thread#stop() has been deprecated, why it has been deprecated and what to do instead.
I recommend that you create a small compilable and runnable demo program and post it here, an SSCCE (see the link below).
Did you read the API documentation what it has to say about that stop() method? Even more you are trying to stop a brand new Thread before it even has started.
Originally Posted by greatmajestics
Jos, I beat you in this one, but you got the draw in the other thread. So I guess that makes us even.
Yep, it's even but it's Sunday so it doesn't count ;-)
Originally Posted by Fubarable