问题
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 ?
回答1:
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.
Have a look at SwingWorker and Using a Swing Worker Thread.
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)
来源:https://stackoverflow.com/questions/8799365/java-animated-gif-and-mysql-connection