import java.awt.*;
import java.applet.*;
import java.lang.*;
import java.util.*;

public class Vettore{

      private protected Graphics pict;
      private protected Color color;
      private protected int x,y,xi,yi;
 
      public Vettore(Graphics img,Color color,int px,int py,int pxi,int pyi){
         
          this.pict = img;
          this.x = px;
          this.y = py;
          this.xi = pxi;
          this.yi = pyi;
          this.color = color;
         
      }

      public void setCoordinates(int px,int py,int pxi,int pyi){

          this.x = px;
          this.y = py;
          this.xi = pxi;
          this.yi = pyi;
 
      }          

      public void setLastCoordinates(int pxi,int pyi){

          this.xi = pxi;
          this.yi = pyi;
 
      }          

      public void Draw(){

         pict.setColor(this.color);
         pict.drawLine(this.x,this.y,this.xi,this.yi);
         pict.drawLine(xi,yi,xi + (int)( 15*this.getDx()/this.getLenght() + 5*this.getDy()/this.getLenght()),yi + (int)( 15*this.getDy()/this.getLenght() - 5*this.getDx()/this.getLenght()) );
         pict.drawLine(xi,yi,xi + (int)( 15*this.getDx()/this.getLenght() - 5*this.getDy()/this.getLenght()),yi + (int)(15*this.getDy()/this.getLenght() + 5*this.getDx()/this.getLenght()) );
 
      }       

      public void Clear(){

          pict.setColor(Color.black);
          pict.drawLine(this.x,this.y,this.xi,this.yi);
         pict.drawLine(xi,yi,xi + (int)( 15*this.getDx()/this.getLenght() + 5*this.getDy()/this.getLenght()),yi + (int)( 15*this.getDy()/this.getLenght() - 5*this.getDx()/this.getLenght()) );
         pict.drawLine(xi,yi,xi + (int)( 15*this.getDx()/this.getLenght() - 5*this.getDy()/this.getLenght()),yi + (int)(15*this.getDy()/this.getLenght() + 5*this.getDx()/this.getLenght()) );
 
      }   

      public int getDx(){

          return x-xi;

      }

      public int getDy(){

          return y-yi;

      }

      public double getLenght(){

          return Math.sqrt((double) (x-xi)*(x-xi)+(y-yi)*(y-yi));

      }

}


