Tag: eventqueue

Java API“如果不在EDT上运行在EDT上”

只是对我的一些重复代码的思考: Runnable run = new Runnable() { @Override public void run() { // Some EDT code } }; if (!EventQueue.isDispatchThread()) { SwingUtilities.invokeAndWait(run); } else { run.run(); } 它并不是非常烦人,但似乎有一些专有function会为你检查这个,虽然我还没有找到它。

为什么人们在事件队列上运行Java GUI

在Java中,要创建并显示一个新的JFrame ,我只需这样做: public static void main(String[] args) { new MyCustomFrameClass().setVisible(true); } 但是,我见过很多人这样做: public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { new MyCustomFrameClass().setVisible(true); } }); } 为什么? 有什么好处吗?