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
{
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.
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.