Java EventQueue. Why should everything be in invokelater method?

后端 未结 2 1900
春和景丽
春和景丽 2020-12-10 05:41

in the book that i\'m reading, every example of GUI with multithreading has something like that:

public static void main(String[] args) throws Exception
{
           


        
相关标签:
2条回答
  • 2020-12-10 06:27

    Desktop GUI applications usually work in this way. There is one thread for gui and one or several threads for rest of application. Using EventQueue you specify what GUI thread should do from other threads.

    0 讨论(0)
  • 2020-12-10 06:35

    The main thread isn't the same as the EDT. If you add System.out.println(Thread.currentThread().getName() you'll see it print out main within main() and AWT-EventQueue-0 when within the run() method of the Runnable.

    Here is a discussion of the history of the single threaded rule in Swing that might help make things clearer.

    0 讨论(0)
提交回复
热议问题