Java动画GIF和MySQL连接 [英] Java animated GIF and MySQL connection

查看:109
本文介绍了Java动画GIF和MySQL连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作Java Messenger.我做了一个登录对话框,当我单击连接"按钮时,在加载GIF动画时出现.

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.

问题是当我的MySQL连接和查询正在处理时,动画GIF停止移动.

The problem is that the animated GIF stops moving while my MySQL connection and Query are processing.

我将MySQL连接和查询置于新线程中,但仍然相同:

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();
...

如何避免GIF冻结?

推荐答案

当Swing程序需要执行长时间运行的任务时,通常使用工人线程之一,也称为后台线程.

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.

看看 SwingWorker 使用Swing Worker线程.

另请阅读 Swing中的并发有关GUI冻结原因的信息,以及有关使用Swing Worker的工作示例的信息. (通过@camickr)

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)

这篇关于Java动画GIF和MySQL连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆