title: Update a BufferedImage in a JFrame
body: <p>I have a BufferedImage displayed in a JFrame through my own class. I opted to display the BufferedImage using my own class so I can scale it. My paintComponent and update</p>
  
  <pre><code>public class MyBuffIm{
  public void paintComponent(Graphics canvas) {
      if (bi == null) {
      } else {
          //bi, maxWidth, and maxHeight were passed to constructor
          canvas.drawImage(bi, 0, 0, maxWidth, maxHeight, null);
      }
  }
  
  public void update(Graphics canvas) {
      super.update(canvas);
      if(bi != null){
          //Got this from some tutorial in the net.
          //Done out of desperation :|
          paintComponent(bi.getGraphics());
      }
  }
  }
  </code></pre>
  
  <p>I overrode update since the docs are saying something like "If this component is not a lightweight component, the AWT calls the update method in response to a call to repaint". I'm not exactly sure if my component is lightweight or not.</p>
  
  <p>In any case, I have the following code in my Runnable (does not work as I expect it to):</p>
  
  <pre><code>BufferedImage p = SomeMyBuffIm.getBuffIm();
  Vector&lt;Point&gt; randomPixels = getRandomPixels(500);
  int limit = randomPixels.size()
  for (i = 0; i &lt; limit; i++) {
      Point rp = randomPixels.get(i)
      p.setRGB(rp.x, rp.y, Color.red.getRGB());
  }
  SomeMyBuffIm.repaint();
  mainFrame.repaint(); //JFrame call to repaint
  </code></pre>
  
  <p>I'd like to think that, since I'm scaling my image, I just can't discern the difference between the new and old images. But I've tried the largest values for getRandomPixels still to no effect. My test image, by the way, is just a white sheet so red pixels should stand out in it.</p>
  
  <p>Anything wrong I'm doing?</p>