You have seen two ways to start the code for the main form:
Mode 1:
Java.awt.EventQueue.invokeLater (New Runnable () {public void run () { new Mainjframe (). setvisible (true); });
Mode 2
Javax.swing.SwingUtilities.invokeLater (New Runnable () {@Overridepublic void Run () {new Mainjframe (). setvisible (True) ;}});
Swingutilities.invokelater and Eventqueue.invokelater are actually the same. Swingutilities.invokelater is actually called Eventqueue.invokelater.
JDK Source code
public static void Invokelater (Runnable dorun) { eventqueue.invokelater (dorun); }
Swingutilities.invokelater's Javadoc has such an explanation:
Open Declaration void Javax.swing.SwingUtilities.invokeLater (Runnable dorun)
Causes Dorun.run () to is executed asynchronously on the AWT event dispatching thread (that is, EDT). This would happen after all pending AWT events has been processed. This method should is used when a application thread needs to update the GUI. In the following example the Invokelater call queues the Runnable object Dohelloworld on the event dispatching thread and Then prints a message.
Runnable Dohelloworld = new Runnable () {public void run () {System.out.println ("Hello World on" + Thread.currentthre AD ()); }}; Swingutilities.invokelater (Dohelloworld); System.out.println ("This might well is displayed before the other message.");
If Invokelater is called from the event dispatching thread--for example, from a JButton ' s ActionListener--the dorun.ru N () would still is deferred until all pending events has been processed. Note if the Dorun.run () throws an uncaught exception the event dispatching thread would unwind (not the current thread ).
Additional documentation and examples for the This method can is found in Concurrency in Swing.
As of 1.3 This method was just a cover for Java.awt.EventQueue.invokeLater ().
Unlike the rest of Swing, this method can is invoked from any thread.
Parameters:dorun See also:invokeandwait
Event Dispatching thread is often said EDT, Event dispatch Threads
For the mechanism of event distribution, see the following article, which is more comprehensive.
http://blog.itpub.net/13685345/viewspace-374940/
About event mechanisms in Java swing