title: How to fix blinking/flashing
body: <p>Simple program that counts every time you click, however the image seems to blink/flash when clicked too fast.    </p>
  
  <pre><code>import java.awt.*;
  import java.awt.event.*;
  import java.awt.Graphics;
  import javax.swing.*;
  import java.lang.Object;
  import java.net.URL;
  import java.lang.String;
  import java.awt.Font;
  
  
  public class Spaceship extends Canvas
  {
      private Font font1;
      int myX = 100;
      int myY = 400;
      int count = 0;
  </code></pre>
  
  <p>These are the 2 images that flash, the images used shouldn't matter though.</p>
  
  <pre><code>    Image img1 = Toolkit.getDefaultToolkit ().getImage ("spaceship.jpg");
      Image img2 = Toolkit.getDefaultToolkit ().getImage ("background.jpg");
  
      public Spaceship ()
      {
          setSize (new Dimension (1272, 960));
          addMouseListener (new MouseAdapter ()
          {
              public void mousePressed (MouseEvent evt)
              {
                  moveIt (evt);
                  count = count + 1;
              }
          }
          );
      }
  
  
      public void moveIt (MouseEvent evt)
      {
          myY = evt.getY () - 100;
          myX = evt.getX () - 150;
          update ();
      }
  
  
      public void update ()
      {
          repaint ();
      }
  </code></pre>
  
  <p>I assume this issue is in here somewhere but not really sure how to fix it.</p>
  
  <pre><code>    public void paint (Graphics g)
      {
          font1 = new Font ("Serif", Font.BOLD, 36);            
          g.drawImage (img2, 0, 0, this);
          g.drawImage (img1, myX, myY, this);
          g.drawRect (1000, 0, 272, 96);
          g.drawRect (1000, 96, 272, 192);
          g.drawRect (1000, 192, 272, 288);
          g.drawRect (1000, 288, 272, 384);
          g.drawRect (1000, 384, 272, 480);
          g.drawRect (1000, 480, 272, 576);
          g.drawRect (1000, 576, 272, 672);
          g.drawRect (1000, 672, 272, 768);
          g.drawRect (1000, 768, 272, 864);
          g.drawRect (1000, 864, 272, 960);
          g.setFont (font1);
          g.drawString (Integer.toString (count), 500, 100);
  
      }
  
      public static void main (String[] args)
      {
          JFrame frame = new JFrame ("Basic Game");
          frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
          Spaceship ex = new Spaceship ();
          frame.getContentPane ().add (ex);
          frame.pack ();
          frame.setResizable (false);
          frame.setVisible (true);
          ex.requestFocus ();
      }
  }
  </code></pre>
  
  <p>What is it exactly that I'm doing wrong?</p>