Ivan Kesic wrote:Anybody?
Here is how i see this! When i hit start button, this loop (thread starts) and it is a current thread!
There is your primary mistake. When you press the start button, you are in the Event Dispatch Thread. When you start the loop a
new Thread starts. That new Thread will be the 'current Thread' for any code explicitly inside the run() method, but will
not be the current Thread for any code that is not in the run() method.
I made a stop button that when i click it, does: Thread.currentThread.interupt;
When you hit the stop button, the code that gets called is again in the Event Dispatch Thread. So when ou do Thread.currentThread().interrupt() you would be interrupting the Event Dispatch Thread that you User Interface uses, and not your thread that does the looping.
You should
read up on Concurrency in Swing.
You need to store a reference to the Thread you create when you press the Start button so you can access it when you press the Stop button. A basic example would be: