What does this code do exactly public static void mainString

What does this code do exactly?

public static void main(String[] args) {

EventQueue.invokeLater(new Runnable() {

public void run() {

try {

}

catch (Exception e) {

e.printStackTrace();

}

}

Solution

Explanation:

Swing components execution is done in a thread called EDT (Event Dispatching Thread). So you can block the GUI if you want to compute some calculations within this thread for long time.

Swing will take resposible to handle your GUI components with in different threads. At the end you want to update your GUI, which have to be done within the EDT that will take care by Swing container. Lets go to EventQueue.invokeLater. it passes an event at the end of list of Swings events and is processed after all previous GUI events are processed.

EventQueue.invokeAndWait is also posiible here. The difference is, that your calculation thread blocks until your GUI is updated. So it is obvious that this must not be used from the EDT.

Below is the example program

Test.java

import java.awt.EventQueue;
public class Test {
   public static void main(String[] args) {
       EventQueue.invokeLater(new Runnable() {
       public void run() {
       try {
           System.out.println(\"testing\");

//new TestFrame().setVisible(true);
       }
       catch (Exception e) {
       e.printStackTrace();
       }
       }
});
   }
}

What does this code do exactly? public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { } catch (Exception e)

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site