Java animated GIF and MySQL connection

风格不统一 提交于 2020-01-06 15:58:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!