title: Java Swing Dependency Injection
body: <p>I have a Swing GUI, which I build using Netbeans, which up until now used static references to communicate with other classes. </p>
  
  <pre>
                   +----------------------+
                   | MainClass (static)   |
                   |----------------------|
            +------+  -DataList           +-----+
            |      |                      |     |
      static|      +-+--------------+-----+     |static
    reference        |              |           |reference
            |        |new ()        | new ()    |
            |        |              |           |
            |        |              |           |
          +-+--------v----+      +--v-----------+--+
          |               |      |                 |
          | SwingGUIClass |      | ExecClasses     |
          |               |      |                 |
          +--/\-----------+      +-----------------+
             |
            Input file
  </pre>
  
  <p>(For an overview please see this <a href="https://stackoverflow.com/questions/19002534/java-swing-design-guide/19002996">question</a>) I now want to get rid of the static references and use dependency injection.</p>
  
  <pre><code>public class SwingGUI extends javax.swing.JFrame {
      private MainApp ma;
  
      public SwingGUI(MainApp ma) {
             this.ma = ma;
  
      } [...]
  </code></pre>
  
  <p>One point where I struggle is, that the GUI gets started as a Thread, and as such can't have any arguments.</p>
  
  <pre><code> [...]
  //still in SwingGUI.class
  /* Create and display the form */
  java.awt.EventQueue.invokeLater(new Runnable() {
      public void run() {
          new SwingGUI().setVisible(true);
      }
  });
  </code></pre>
  
  <p><strong>How can I inject dependencies while not breaking my code?</strong> Most of the questions here on SO that deal with that topic are about Guice - which at this point I don't want to use.</p>
  
  <p>Thanks.</p>