如何使Label进入线程? [英] How to get Label into thread?

查看:145
本文介绍了如何使Label进入线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先让我向您展示我的代码:

First off let me show you my code:

线程: http://pastebin.com/ie4WD5W8

然后调用线程我使用了以下...

Then to call the thread i used the following...

    randomKeyGen key1 = new randomKeyGen(ranLKey);
    key1.start();

ranLKey是我的标签,我不知道为什么它不起作用.只要我不尝试在线程中放置标签,它就可以工作,但是那会破坏整个目的.因此,上面的代码不能起作用,但是来自 pastebin 的代码似乎很好.希望您能帮助我解决我做错的事情.

ranLKey is my label and I can't figure out why it won't work. As long as I do not try to put a label in the thread it works, but that defeats the entire purpose. So the above code does NOT work, but the code from pastebin seems to be fine. Hopefully you can help me out with what I am doing wrong.

如果有帮助,我正在使用netbeans.之前在多个地方也谈到过这一点.因此,如果您以前见过我,那就告诉我我仍在寻求帮助.

I am using netbeans if that helps at all. Also talked about this before in multiple places. So if you saw me before, then just letting you know I am still looking for help.

感谢进阶!

推荐答案

我认为问题可能出在 mainFrame setKey(String)和/或 getKey()调用.他们不是在GUI中玩游戏吗?如果是这样,他们应该通过事件分发线程,类似于标签设置(尝试 invokeAndWait(Runnable)).此外,建议在创建新的可运行对象( isEventDispatchThread())之前先检查事件分配线程.

I believe the issue might be in the mainFrame's setKey(String) and/or getKey() calls. Aren't they play with something in GUI? If so they should go through event dispatch thread, similar to the label setting (try invokeAndWait(Runnable)). What's more it's advised to check first for the event dispatch thread before creating a new runnable (isEventDispatchThread()).

这篇关于如何使Label进入线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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