title: how to draw a moving animation line between two different points
body: <p>I'm doing a project about linking immobile points with an animated point.
  I'm using this and I want to do it with a random number of points which are located randomly. The source code is use for only 2 locations I want to do it with all points like I take the x and y from point 1. I want it to go to other location point 2 and point 3 for example.</p>
  <p><strong>PS:</strong> I'm a french and not an English speaker. Sorry for the mistakes and I'm new in java.</p>
  <h3>Panneau.java</h3>
  <pre><code>package animation;
  
  /**
  *
  * @author ilies
  */
  import java.awt.Color;
  import java.awt.Graphics;
  import javax.swing.JPanel;
  
  public class Panneau extends JPanel {
   private int posX = -50;
    private int posY = -50;
    public void paintComponent(Graphics g){
      //On choisit une couleur de fond pour le rectangle
      g.setColor(Color.white);
      //On le dessine de sorte qu'il occupe toute la surface
      g.fillRect(0, 0, this.getWidth(), this.getHeight());
      //On redéfinit une couleur pour le rond
      g.setColor(Color.red);
      //On le dessine aux coordonnées souhaitées
      g.fillOval(posX, posY, 50, 50);
    }
    public int getPosX() {
     return posX;
     }
    public void setPosX(int posX) {
      this.posX = posX;
    }
    public int getPosY() {
      return posY;
    }
    public void setPosY(int posY) {
      this.posY = posY;
    }
  }  
  </code></pre>
  <h3>Fenetre.java</h3>
  <pre><code>package animation;
  
  /**
   *
   * @author ilies
   */
   import java.awt.Dimension; 
   import javax.swing.JFrame;
  
  public class Fenetre extends JFrame{
    private Panneau pan = new Panneau();
    public Fenetre(){        
     this.setTitle(&quot;Animation&quot;);
     this.setSize(300, 300);
     this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     this.setLocationRelativeTo(null);
     this.setContentPane(pan);
     this.setVisible(true);
     go();
     }
     private void go(){
   
      for(int i = -50; i &lt; pan.getWidth(); i++){
        int x = pan.getPosX(), y = pan.getPosY();
        x++;
        y++;
        pan.setPosX(x);
        pan.setPosY(y);
        pan.repaint();  
        try {
          Thread.sleep(10);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
    }       
  }
  </code></pre>
  <h3>Animation.java</h3>
  <pre><code>package animation;
  
  /**
  *
  * @author ilies
  */
  public class Animation {
  
     /**
      * @param args the command line arguments
      */
      public static void main(String[] args) {
         Fenetre fen = new Fenetre();
         // TODO code application logic here
      }
  
  }
  </code></pre>