gpt4 book ai didi

java - SwingUtilities.invokeLater ...有一个invokeNow吗?

转载 作者:行者123 更新时间:2023-12-01 23:03:08 25 4
gpt4 key购买 nike

I had a problem earlier我试图将对象添加到 Canvas 中,但 SwingUtilities.invokeLater 尚未真正完成其工作。我确实需要能够可靠地向此 JPanel 添加内容,但我不断遇到同样的错误。下面的代码有更好的替代方案吗?

private void startNewGame() {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
gameFrame = new InvadersGameFrame();
}
});
}

最佳答案

参见SwingUtilities.invokeAndWait(Runnable)其中:

Causes doRun.run() to be executed synchronously on the AWT event dispatching thread. This call blocks until all pending AWT events have been processed and (then) doRun.run() returns. This method should be used when an application thread needs to update the GUI.

关于java - SwingUtilities.invokeLater ...有一个invokeNow吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23209388/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com