- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我的 previous problem 有问题.我在代码库的其他地方也有代码 SwingUtillities.invokeAndWait
,但是当我删除它时,gui 不会刷新。如果我不删除它,我得到的错误是:
Exception in thread "AWT-EventQueue-0" java.lang.Error: Cannot call invokeAndWait from the event dispatcher thread
at java.awt.EventQueue.invokeAndWait(Unknown Source)
at javax.swing.SwingUtilities.invokeAndWait(Unknown Source)
at game.player.humanplayer.model.HumanPlayer.act(HumanPlayer.java:69)
HumanPlayer.act 中的代码是:
public Action act(final Action[] availiableActions) {
try {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
gui.update(availiableActions);
}
});
}
catch (InterruptedException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
synchronized(performedAction){
while(!hasPerformedAction()){
try {
performedAction.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
setPerformedAction(false);
}
return getActionPerfomed();
}
由于屏幕不绘制而处于调试状态时的线程图像: alt text http://img684.imageshack.us/img684/6669/69288941.png
堆栈的文本版本:
ui.startup.LoginScreen at localhost:51050
-> Deamon Thread [AWT-Windows] (Running)
-> Thread [AWT-Shutdown] (Running)
-> Thread [AWT-EventQueue-0] (Running)
-> Thread [DestroyJavaVM] (Running)
最佳答案
答案是而不是打电话
new GameInitializer(userName, player, Constants.BLIND_STRUCTURE_FILES.get(blindStructure), handState);
从 EDT 开始,让它在新的(非 EDT)线程上执行,以便稍后在调用 invokeAndWait
时它可以正常运行,因为运行该命令的线程不是 EDT。修改后的代码如下:
Thread t = new Thread(new Runnable() {
@Override
public void run() {
new GameInitializer(userName, player, Constants.BLIND_STRUCTURE_FILES.get(blindStructure), handState);
}
});
t.start();
关于java - 从 EDT 调用 invokeAndWait,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2435397/
只是想一想我的一些重复代码: Runnable run = new Runnable() { @Override public void run() { // Some EDT cod
我在 Java 库中使用一个 API,它从事件分派(dispatch)线程调用并要求我返回一个完全初始化的 UI 组件。它看起来像这样: public JDialog createDialog()
我有一个在 EDT 上运行的方法,我想让它在一个新的(非 EDT)线程上执行一些事情。我当前的代码如下: @Override public void actionPerformed(Actio
我有以下测试方法: @Test public void f3KeystrokeShowsHotkeysDialog() throws AWTException{ App app = new A
我正在开发一个项目,该项目需要进行一些密集的数学计算(矩阵、 vector 数组等),因此我很自然地将工作分成多个作业,并将它们提交给 CompletionService 以并行执行工作. 每个作业对
所以我对 MVC 结构还很陌生。我真的很困惑何时何地在 EDT 上添加我的 Gui 部分。这是我真正困惑的地方: public class ECPS_MVC { //edt? Ecps
如果从 EDT 线程调用某些方法出现未经检查的异常,会发生什么情况?它能保持 GUI 的响应能力还是什么?谢谢您 最佳答案 Before restarting, does the EDT shutdo
我对了解 Swing 乐和 EDT 的追求再次继续...... 由于 EDT 是唯一的 EDT,所以我现在想知道哪些方法、构造函数和任何其他内容应该在 EDT 中完成。我知道一般规则,几乎所有创建 S
该示例不断绘制各种颜色的方 block 。方 block 的数量取决于 JFrame 的大小。 在执行示例时,使用鼠标放大或缩小尺寸框,将会增加或减少可见闪烁方 block 的数量。 该帧的时间栏显示
我按照别人告诉我的方式处理我的游戏循环,添加了 Swing 计时器等(除了重写paintComponent,因为它在这种情况下不适用),但我的游戏循环拒绝调用事件调度线程。因此,JFrame 不会关闭
正如我在 earlier post 上与 Inerdia 讨论的那样, 事情仍然很奇怪当我在一些 JPanel 中(肯定是 EDT - 我用方法检查进行了检查)然后我调用一些动画线程(线程扩展线程)来
我想创建新线程(用于服务器)。我有 textArea 来放置日志,我创建了一个新的类状态来处理它。我为对象“服务器”运行新线程,尝试将状态对象“传递”到服务器,并且执行 status.setStatu
我正在用 Java 编写 Sugarscape 模拟,需要一个工作的 GUI。 Sugarscape 是一种空间景观,由(糖的)瓷砖和移动和消耗糖的代理组成。为简单起见,我只有一个代理,没有糖——我只
如何知道 EDT 被阻塞(不是直观地而是通过检查线程本身)?有办法吗? 我正在完成最后的大学毕业任务,其中有一堆图表,但对 Swing EDT(通常是 Java)知之甚少。 看看这篇文章: Swin
我一直在问很多关于我最近正在进行的项目的问题。这是我所处的场景,任何帮助或指出正确方向都会有很大帮助...... 这是一个由一个服务器和多个客户端构建的网络程序。每个客户端都有一个 GUI,它必须根据
我有一个在 EDT 内执行的方法。事情是这样的: myMethod() { System.out.prinln(SwingUtilities.isEventDispatchThread());
我正在尝试学习 Swing 的复杂性,并且已经阅读了大量有关事件调度线程的内容。我明白这是为了什么,但是我正在为以下概念而苦苦挣扎: 我有一个以正常方式调用的 JFrame: public cla
我想知道 Java 中的事件调度线程何时启动。 它是主线程,还是在Window/Frame构造函数中启动? 如果检测到 AWT/Swing 的使用,是否由 JVM 启动? 最佳答案 主线程不是 EDT
我认为提出问题的最简单方法是逐步解决问题。我对 EDT 的某些工作原理有些困惑。 是否有任何对象是从在 EDT 上创建的 Swing 组件创建的? 要扩展这个问题,如果我创建一个 JFrame,并在其
嗨,我想在 EDT 之外完成一项任务: new Thread(new Runnable(){ @Override public void
我是一名优秀的程序员,十分优秀!