I a making a Java Messenger. I did a login dialog and when I click on the connect button, an animated GIF appears while it's loading.
The problem is that the animated GIF stops moving while my MySQL connection and Query are processing.
I throw the MySQL connection and query in a new thread but still the same :
Thread connectionThread = new Thread(new Runnable() {
public void run() {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
//Database conection
OlaDB.createConnection();
...
What can I do to avoid my GIF freezing ?
解决方案
When a Swing program needs to execute a long-running task, it usually uses one of the worker threads, also known as the background threads.
also Read up on on Concurrency in Swing for more information on why the GUI freezes and for a working example of using a Swing Worker. (via @camickr)