Here you can find the source of drawArrow(Graphics2D g2d, double x1, double y1, double x2, double y2)
public static void drawArrow(Graphics2D g2d, double x1, double y1, double x2, double y2)
//package com.java2s; //License from project: Open Source License import java.awt.Graphics2D; import java.awt.geom.AffineTransform; public class Main { /** Draw an arrow, useful for debug */ public static void drawArrow(Graphics2D g2d, double x1, double y1, double x2, double y2) { Graphics2D g = (Graphics2D) g2d.create(); double dx = x2 - x1, dy = y2 - y1; double angle = Math.atan2(dy, dx); int len = (int) Math.sqrt(dx * dx + dy * dy); AffineTransform at = AffineTransform.getTranslateInstance(x1, y1); at.concatenate(AffineTransform.getRotateInstance(angle)); g.transform(at);/*from w w w. java 2 s .com*/ // Draw horizontal arrow starting in (0, 0) g.drawLine(0, 0, len, 0); g.fillPolygon(new int[] { len, len - 6, len - 6, len }, new int[] { 0, -6, 6, 0 }, 4); } }