protected void drawArrow(Graphics g,int nPosX1,int nPosY1,int nPosX2,int nPosY2){
  g.drawLine(nPosX1,nPosY1,nPosX2,nPosY2);
  if (nPosX1 == nPosX2) {
    if (nPosY1 < nPosY2) {
      g.drawLine(nPosX2,nPosY2,nPosX2 + 4,nPosY2 - 8);
      g.drawLine(nPosX2,nPosY2,nPosX2 - 4,nPosY2 - 8);
    }
 else {
      g.drawLine(nPosX2,nPosY2,nPosX2 + 4,nPosY2 + 8);
      g.drawLine(nPosX2,nPosY2,nPosX2 - 4,nPosY2 + 8);
    }
  }
 else {
    double hyp=0, base=0, perp=0, theta, beta;
    int nPosX3=0, nPosY3=0;
    if (nPosX2 < nPosX1) {
      base=nPosX1 - nPosX2;
      hyp=Math.sqrt((nPosX2 - nPosX1) * (nPosX2 - nPosX1) + (nPosY2 - nPosY1) * (nPosY2 - nPosY1));
      theta=Math.acos(base / hyp);
    }
 else {
      base=nPosX1 - nPosX2;
      hyp=Math.sqrt((nPosX2 - nPosX1) * (nPosX2 - nPosX1) + (nPosY2 - nPosY1) * (nPosY2 - nPosY1));
      theta=Math.acos(base / hyp);
    }
    beta=30 * Math.PI / 180;
    hyp=8;
    base=Math.cos(theta - beta) * hyp;
    perp=Math.sin(theta - beta) * hyp;
    nPosX3=(int)(nPosX2 + base);
    if (nPosY1 < nPosY2) {
      nPosY3=(int)(nPosY2 - perp);
    }
 else {
      nPosY3=(int)(nPosY2 + perp);
    }
    g.drawLine(nPosX2,nPosY2,nPosX3,nPosY3);
    base=Math.cos(theta + beta) * hyp;
    perp=Math.sin(theta + beta) * hyp;
    nPosX3=(int)(nPosX2 + base);
    if (nPosY1 < nPosY2) {
      nPosY3=(int)(nPosY2 - perp);
    }
 else {
      nPosY3=(int)(nPosY2 + perp);
    }
    g.drawLine(nPosX2,nPosY2,nPosX3,nPosY3);
  }
}

protected void drawArrow ( Graphics g , int nPosX1 , int nPosY1 , int nPosX2 , int nPosY2 ) { g . drawLine ( nPosX1 , nPosY1 , nPosX2 , nPosY2 ) ; if ( nPosX1 == nPosX2 ) { if ( nPosY1 < nPosY2 ) { g . drawLine ( nPosX2 , nPosY2 , nPosX2 + 4 , nPosY2 - 8 ) ; g . drawLine ( nPosX2 , nPosY2 , nPosX2 - 4 , nPosY2 - 8 ) ; } else { g . drawLine ( nPosX2 , nPosY2 , nPosX2 + 4 , nPosY2 + 8 ) ; g . drawLine ( nPosX2 , nPosY2 , nPosX2 - 4 , nPosY2 + 8 ) ; } } else { double hyp = 0 , base = 0 , perp = 0 , theta , beta ; int nPosX3 = 0 , nPosY3 = 0 ; if ( nPosX2 < nPosX1 ) { base = nPosX1 - nPosX2 ; hyp = Math . sqrt ( ( nPosX2 - nPosX1 ) * ( nPosX2 - nPosX1 ) + ( nPosY2 - nPosY1 ) * ( nPosY2 - nPosY1 ) ) ; theta = Math . acos ( base / hyp ) ; } else { base = nPosX1 - nPosX2 ; hyp = Math . sqrt ( ( nPosX2 - nPosX1 ) * ( nPosX2 - nPosX1 ) + ( nPosY2 - nPosY1 ) * ( nPosY2 - nPosY1 ) ) ; theta = Math . acos ( base / hyp ) ; } beta = 30 * Math . PI / 180 ; hyp = 8 ; base = Math . cos ( theta - beta ) * hyp ; perp = Math . sin ( theta - beta ) * hyp ; nPosX3 = ( int ) ( nPosX2 + base ) ; if ( nPosY1 < nPosY2 ) { nPosY3 = ( int ) ( nPosY2 - perp ) ; } else { nPosY3 = ( int ) ( nPosY2 + perp ) ; } g . drawLine ( nPosX2 , nPosY2 , nPosX3 , nPosY3 ) ; base = Math . cos ( theta + beta ) * hyp ; perp = Math . sin ( theta + beta ) * hyp ; nPosX3 = ( int ) ( nPosX2 + base ) ; if ( nPosY1 < nPosY2 ) { nPosY3 = ( int ) ( nPosY2 - perp ) ; } else { nPosY3 = ( int ) ( nPosY2 + perp ) ; } g . drawLine ( nPosX2 , nPosY2 , nPosX3 , nPosY3 ) ; } }
this method draws an arrow on a line from ( x1 , y1 ) to ( x2 , y2 ) . the arrow head is seated on ( x2 , y2 ) and is in the direction of the line . if the arrow is needed to be drawn in the opposite direction then simply swap the order of ( x1 , y1 ) and ( x2 , y2 ) when calling this function .
