title: Applet repaint frequency
body: <p>I want to create a Rubber-banding line using applet. Here is my code:</p>
  
  <pre><code>import java.applet.*;
  import java.awt.*;
  import java.awt.event.*;
  import java.util.Vector;
  
  public class RubberLines extends Applet implements MouseMotionListener {
      public void init() {
          addMouseMotionListener(this);
      }    
      public void mouseDragged(MouseEvent e) {
          draw=true;
          X.add(e.getX());
          Y.add(e.getY());
          System.out.println(X.get(0));
          System.out.println("mouse is being dragged at location (" + e.getX() + ", " + e.getY() + ")");
      }    
      public void mouseMoved(MouseEvent e) {
          System.out.println("mouse is being moved at location (" + e.getX() + ", " + e.getY() + ")");
      }     
      public void paint(Graphics g) {
                  initX=X.get(0);
                  initY=Y.get(0);
                  finalX=X.get(X.size()-1);
                  finalY=Y.get(Y.size()-1);
                  //g.drawLine(0, 0, 100, 100);
                  if(draw)
          g.drawLine(initX, initY, finalX, finalY);
          g.setColor(Color.green);
             System.out.println(initX);
             System.out.println(finalY); 
  
             //repaint();    
      }   
      int initX,initY;
      int finalX,finalY;
      Vector&lt;Integer&gt; X=new Vector&lt;Integer&gt;();
      Vector&lt;Integer&gt; Y=new Vector&lt;Integer&gt;();
      boolean draw=false;    
  }
  </code></pre>
  
  <p>However, the line didn't show up when I dragged the mouse until I change the size of applet(which means repaint). But when I added <code>repaint()</code>, the applet just repaints itself non-stop.</p>
  
  <p>How to understand this <code>repaint()</code> and how to fix the problem please?</p>