Java EventQueue. Why should everything be in invokelater method?

后端 未结 2 1901
春和景丽
春和景丽 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: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.

提交回复
热议问题