title: Java Event-Dispatching Thread explanation
body: <p>I've recently started learning and exploring the basics of GUI programming in Java.</p>
  
  <p>Having been programming for a while I have only done backend work or work and as a result the closest I've gotten to user interfaces is the command console (embarrassing I know).</p>
  
  <p>I'm using Swing and as far as I can gather that means by extension I am also using AWT.</p>
  
  <p>My question is based on this piece of code:</p>
  
  <pre><code>java.awt.EventQueue.invokeLater(new Runnable() {
      public void run() {
          new frame.setVisible(true);
      }
  } );
  </code></pre>
  
  <p>I have been researching this for a while as I wanted to fully understand this strange piece of code and have come across the term 'Event-Dispatching Thread' multiple times. Correct me if I'm wrong but as I understand it; it has to do with using multiple threads and how Java Swing interprets those threads. I gather as well that the above code is used to make sure all the threads are 'safe' before it creates the window, hence the invokeLater?</p>
  
  <p>I have read that:</p>
  
  <blockquote>
    <p>"You can only call methods that operate on the frame from the Event-Dispatching Thread"</p>
  </blockquote>
  
  <p>and that only under certain circumstances can you call methods that operate on the frame from the main method. </p>
  
  <p><strong>Can somebody please clarify to me what exactly the Event-Dispatching Thread is?</strong></p>
  
  <p><strong>How it relates to multiple threads of execution and how those threads are not safe to be called from the main method? Also why do we need this invokeLater?</strong></p>
  
  <p><strong>Can we not just create the window as any other object?</strong></p>
  
  <p>I've hit a bit of a road block in my research as I'm not grasping these relations and ideas.</p>
  
  <p>A side note is that I like to base my knowledge on in-depth understanding as I believe this leads to the best overall outcome and as a result the best programs. If I understand in-depth how something works then you can use the tips and tweaks effectively rather than just parroting them back in to code, so please don't be afraid to give me some extra in-depth explanations and broaden my knowledge.</p>
  
  <p>Thank you.</p>