简体   繁体   English

Swing事件线程Java

[英]Swing Event Thread Java

In this code HelloWorldApp simply extends JFrame . 在此代码中,HelloWorldApp只是扩展了JFrame。 Why dont i need to put the 'app' object definition in the invokeLater method ? 为什么我不需要将“ app”对象定义放入invokeLater方法中? And why 'app' need to be final ? 为什么“ app”必须是最终的? Thanks 谢谢

final HelloWorldApp app = new HelloWorldApp();
SwingUtilities.invokeLater( new Runnable() 
{
    public void run() 
    {
        app.createAndShowGUI();
    }
});
  1. All changes to the UI state of swing components has to be done within the EDT (Event Dispatch Thread). 摆动组件的UI状态的所有更改都必须在EDT(事件调度线程)内完成。 Therefore the definition of the 'app' can be done in the main thread as long as in the constructor HelloWorldApp() doesnt create UI components or changes the state of UI components. 因此,只要在构造函数HelloWorldApp()不创建UI组件或更改UI组件的状态,就可以在主线程中完成“ app”的定义。

  2. I see no reason for specifying the class as final. 我认为没有必要将类指定为final。 In the latest tutorial it is not final any longer. 在最新的教程中,它不再是最终的。 See Hello World tutorial 参见Hello World教程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM