title: Using repaint() to draw on JPanel which is added to JFrame
body: <p>Attempting to draw my rectangle across the screen horizontally in realtime. When I run this I get nothing but the JFrame. I'm not sure what I am missing aside from maybe some type of threading freeze to redraw the shape maybe?</p>
  <pre><code>public class ScreenTest extends JFrame {
      
      int rectY = 50;
      
      public ScreenTest()
      {
          setSize(300,200);
          setDefaultCloseOperation(EXIT_ON_CLOSE);
          setVisible(true);
          
      }
      
      private class DrawPanel extends JPanel {
          
          protected void paintComponent(Graphics g) {
              super.paintComponent(g);
              g.setColor(Color.GREEN);
              g.fillRect(80, rectY, 50, 50);
         }
      }
      
      public void Draw()
      {
          DrawPanel test = new DrawPanel();
          add(test);
          
          while (rectY &lt; 200)
          {
              rectY = rectY + 10;
              test.repaint();
          }
  
      }
  
      public static void main(String[] args) {
          // TODO Auto-generated method stub
          ScreenTest myWindow = new ScreenTest(); 
          myWindow.Draw();
      }
      
  }
  </code></pre>