title: Java - Swing GUI doesn't load
body: <p>I've been trying to learn java for a few weeks now, and I'm working on a pretty simple autoclicker.
  The clicker itself works, but my problem is that my GUI never shows up.
  The GUI runs just fine when I run the GUI file itself, but when I'm trying to run it from my main program (different file) it never shows. The clicker works fine all the time though. I'm sure the problem is something really simple that I have simply missed, but this is now my 4th day without any clue on what might be wrong with it, so decided I'd ask here.</p>
  
  <p>Beware - the code is really messy atm, because I've been trying pretty much everything possible to get it working.</p>
  
  <p>This is the code in the main program trying to run the GUI.</p>
  
  <pre><code>package autoclicker;
  
  import java.awt.AWTException;
  
  /**
   * The main program for the autoclicker.
   */
  public class AutoClicker {
      public static void main(String[] args) throws AWTException {
          Click click = new Click(true);
          click.clicker();
          try {
              Swingerinos sw = new Swingerinos();
              sw.initialize();
          }
          catch (AWTException e) { e. printStackTrace(); System.exit(-1); }
      }
  }
  </code></pre>
  
  <p>And this is the whole GUI file.</p>
  
  <pre><code>package autoclicker;
  
  import java.awt.*;
  
  import javax.swing.JFrame;
  import javax.swing.JPanel;
  import javax.swing.JButton;
  import javax.swing.JLabel;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.awt.event.WindowEvent;
  import java.awt.event.WindowListener;
  
  
  public class Swingerinos extends Click implements WindowListener,ActionListener {
  
      private int numClicks = 0;
      TextField text;
  
      private JFrame frame;
      /**
       * @wbp.nonvisual location=181,19
       */
      private final JLabel lblAutoclicker = new JLabel("AutoClicker");
  
      /**
       * Launch the application.
       */
      public static void main(String[] args) {
          EventQueue.invokeLater(new Runnable() {
              public void run() {
                  try {
                      Swingerinos window = new Swingerinos();
                      window.frame.setVisible(true);
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
              }
          });
      }
  
      /**
       * Create the application.
       */
      public Swingerinos() throws AWTException {
          initialize();
      }
  
      /**
       * Initialize the contents of the frame.
       */
      public void initialize() {
          frame = new JFrame();
          frame.setBounds(100, 100, 450, 109);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
          JPanel panel = new JPanel();
          frame.getContentPane().add(panel, BorderLayout.WEST);
  
          JButton btnNewButton = new JButton("Toggle On / Off");
          text = new TextField(20);
          text.setLocation(100, 100);
          btnNewButton.addActionListener( this);
          btnNewButton.setToolTipText("Toggles the  autoclicker on / off.");
          panel.add(btnNewButton);
          panel.add(text);
          frame.setVisible(true);
      }
  
      public void actionPerformed(ActionEvent e) {
          toggle();
          numClicks++;
          text.setText(""+numClicks);
      }
  
  
      public void windowClosing(WindowEvent e) {
          System.exit(0);
      }
  
      public void windowOpened(WindowEvent e) {}
      public void windowActivated(WindowEvent e) {}
      public void windowIconified(WindowEvent e) {}
      public void windowDeiconified(WindowEvent e) {}
      public void windowDeactivated(WindowEvent e) {}
      public void windowClosed(WindowEvent e) {}
  
  }
  </code></pre>
  
  <p>I know the GUI file is really messy (there's 2x initialize(), one in the main program and one in the GUI file, and lots of other stuff, but I'm just too confused as for what to do now.</p>
  
  <p>EDIT: I added the whole main program code, also this is the code for the autoclicker.</p>
  
  <pre><code>package autoclicker;
  
  import java.awt.*;
  import java.awt.event.InputEvent;
  
  public class Click {
      private boolean active;
      private Robot robot;
  
      public Click(boolean active, Robot robot) {
          this.active = active;
          this.robot = robot;
      }
  
      public Click() throws AWTException {
          this(false, new Robot());
      }
  
      public Click(boolean active) throws AWTException {
          this(active, new Robot());
      }
  
      //TODO: add click.toggle() to somewhere and control da clicker
      public void toggle() {
          active = !active;
      }
  
      public void clicker() {
          while (active) {
              robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
              robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
              robot.setAutoDelay(10000);
          }
      }
  }
  </code></pre>