title: Image flickers on repaint()
body: <p>I figured out the solution for my <a href="https://stackoverflow.com/questions/10430003/image-overlay-is-flickering">previous question</a> which landed me into new problem.</p>
  
  <p>In the following code im moving an image around a JFrame using arrow keys. but every time i press an arrow key the image seems to flicker which is quite noticeable when a key is pressed continuously. </p>
  
  <pre><code>import java.awt.Graphics;
  import java.awt.event.KeyEvent;
  import java.awt.event.KeyListener;
  import java.awt.image.BufferedImage;
  import java.io.IOException;
  import javax.imageio.ImageIO;
  import javax.swing.JFrame;
  
  
  public class TestProgram extends JFrame implements KeyListener {
      private BufferedImage TestImage;
      private int cordX = 100;
      private int cordY = 100;
  
      public TestProgram() {
          setTitle("Testing....");
          setSize(500, 500);
          imageLoader();
          setVisible(true);
      }
  
      public void imageLoader() {
          try {
              String testPath = "test.png";
              TestImage = ImageIO.read(getClass().getResourceAsStream(testPath));
  
          } catch (IOException ex) {
              ex.printStackTrace();
          }
  
          addKeyListener(this);
      }
  
      @Override
      public void paint(Graphics g) {
          super.paint(g);
          g.drawImage(TestImage, cordX, cordY, this);
      }
  
      public static void main(String[] args) {
          new TestProgram();
      }
  
  
      public void keyPressed(KeyEvent ke) {
          switch (ke.getKeyCode()) {
              case KeyEvent.VK_RIGHT: {
                  cordX+=5;
              }
              break;
              case KeyEvent.VK_LEFT: {
                  cordX-=5;
              }
              break;
              case KeyEvent.VK_DOWN: {
                  cordY+=5;
              }
              break;
              case KeyEvent.VK_UP: {
                  cordY-=3;
              }
              break;
          }
          repaint();
      }
  
      public void keyTyped(KeyEvent ke) {}
  
      public void keyReleased(KeyEvent ke) {}
  }
  </code></pre>
  
  <p>Is there any solution to avoid that?</p>
  
  <p>EDIT: above is the complete working code. I'm finding it difficult to incorporate doublebuffer in it. can anyone help me in that part?</p>