title: Swing Timer on main(String[]) exits the program after the time specified
body: <p>I need to generate a new <code>Thread</code> every 2 seconds. So I tried to use the <code>Timer</code> class in the <code>main(String[])</code> method but my program just exists after the milliseconds I specified in the <code>Timer</code> constructor.</p>
  
  <p><strong>Program.java</strong>:</p>
  
  <pre><code>public class Program
  {
      private static int panelWidth;
      private static int panelHeight;
  
      private static MyPanel panel = new MyPanel();
  
      public static void main(String[] args) 
      {   
          MyFrame frame = new MyFrame();
          frame.add(Program.panel);
  
          Program.panelWidth = frame.getWidth();
          Program.panelHeight = frame.getHeight();
  
          Timer generateBallTimer = new Timer(2000, new GenerateBalls());
          while (true)
          {
              generateBallTimer.start();
          }
  
  
  
      } // End of main method
  
  
      /**
       * Generate a new ball every 2 seconds.
       *
       */
      public static class GenerateBalls implements ActionListener
      {
          @Override
          public void actionPerformed(ActionEvent e)
          {
              Program.generateBalls();
          }
      }
  
      public static void generateBalls()
      {
          // Generate a ball each 2 seconds
          while (true)
          {
              Program.panel.balls.add(new Ball(Program.panel));
          }
      }
  
  
  
  } // End of program class
  </code></pre>
  
  <p>If in the <code>Timer</code> constructor I will specify 3000ms my program will be closed after 3 seconds and so on.</p>
  
  <p>What am I doing wrong here?</p>