Disclaimer: I\'m not using my program for anything malicious, even though it\'s name is Spambot. I\'m only using it for practice.
Edit: My problem is th
What you should be using in any GUI application is not multithreading, but event-driven programming. That means never execute long-running loops inside an event handler, and never, ever, call Thread.sleep
in one.
Instead, a delayed GUI action must be scheduled on a Swing Timer, and the loop body must be put into the handler which you submit to the timer.
If you don't have a delayed action, but truly a long-running task (that would mean you do a lot of computation or wait for I/O), only then would you need a background thread to do the work. In that case you would use the SwingWorker
to communicate the task's results back to the GUI.