title: What is the fastest way to draw pixels in Java
body: <p>I have some code that generates particles at random locations, and moving in random directions and speed.</p>
  
  <p>Each iteration through a loop, I move all the particles, and call repaint on my jpanel.</p>
  
  <p>For 1,000 particles, I'm getting around 20 to 30 frames per second.  I plan to eventually have 100,000 to 1,000,000 particles.  </p>
  
  <p>In paint, I only create a new bufferedimage if the window has changed size.  I draw the pixels to the bufferedimage, and then call drawImage to display the image.</p>
  
  <p>Each particle is a single pixel, and I have determined that all the time is taken up actually drawing the pixels.  So, increasing the number of particles will drastically reduce the frame rate.</p>
  
  <p>I've tried g.drawline(x,y,x+1,y), img.setRGB(x,y,color), getting an array of pixels by calling img.getRaster().getDataBuffer().getData(), then setting pixelData[y*width+x] = color.</p>
  
  <p>I only get a small difference in the frame rate with these different ways of drawing the pixels.</p>
  
  <p>Here's my question:  What is the fastest way to draw pixels?  Is bufferedimage even the way to go?</p>
  
  <p>Thanks.</p>