title: How do I properly paint to a frame/panel?
body: <p>I've tried many variations of everything at the bottom of this class and so far nothing works. Occasionally an edit will cause the print statement to work, but the window just always opens at a size that isn't even the one I set it up and stays blank. I don't know what's wrong with it. I'm trying to print 1024 rectangles on my window with a pause inbetween each print. The values are right, they're just not getting painted for some reason. Changing the method to paintComponent doesn't seem to do much either. The code is long, so here's a pastebin: <a href="http://pastebin.com/ridipz3X" rel="nofollow">http://pastebin.com/ridipz3X</a>. The important stuff is at the end though:</p>
  
  <pre><code>JFrame frm = new TestEnvironment();
                          frm.setSize(1152, 1152);
                          frm.setVisible(true);
                          JPanel panel = new JPanel();
                          frm.add(panel);
                          t = 0;
                          i = 0;
                          while (t &lt; x - 1) {
  
                                  panel.repaint();
  
                                  j++;
                                  t++;
                                  Thread.sleep(10000);
                          }
  
                  } catch (Exception e) {
                          System.out.println(e);
                          e.printStackTrace();
                  }
          }
  public void paint(Graphics g) {
                  g.setColor(Color.black);
                  g.setColor(getBackground());
                  g.fillRect(0, 0, getWidth(), getHeight());
                  g.setColor(getForeground());
                  try {
                          for (int h = 0; h &lt; 1152; h++) {
                                  g.drawRect(h, 0, (int) (((ampArray[h][j]) / maxFreq) * 1152),
                                                  1);
                                  g.fillRect(h, 0, (int) (((ampArray[h][j]) / maxFreq) * 1152),
                                                  1);
                                  System.out.println(ampArray[h][j]);
                          }
                  } finally {
                          g.dispose();
                  }
          }
  }
  </code></pre>
  
  <p>Thanks</p>