How to draw Arrow Line in Applet Java code example

public static void drawArrowLine(Graphics g, int i, int j, int k, int l, int i1)
    {
        double d = Math.sqrt((k - i) * (k - i) + (l - j) * (l - j));
        double d1 = (double)(-(k - i)) / (double)(l - j);
        double d2 = 6D / Math.sqrt(1.0D + d1 * d1);
        double d3 = 6D / Math.sqrt(1.0D + 1.0D / d1 / d1);
        if(d1 < 0.0D)
            d3 = -d3;
        double d4 = (double)k - (double)(10 * (k - i)) / d;
        double d5 = (double)l - (double)(10 * (l - j)) / d;
        drawLine(g, i, j, (int)d4, (int)d5, i1);
        int ai[] = {
            (int)(d4 - d2), k, (int)(d4 + d2)
        };
        int ai1[] = {
            (int)(d5 - d3), l, (int)(d5 + d3)
        };
        g.fillPolygon(ai, ai1, 3);
    }
}

Comments

  1. an easier way to look at this method then with the weird variable names given is:

    void drawArrow(Graphics2D g, int x1, int y1, int x2, int y2);

    Not sure what i1 is/does as it is only used with drawLine, and that method's implementation was not supplied with us.

    ReplyDelete

Post a Comment

Recent Post

Recent Posts Widget

Popular posts from this blog

Capture image from webcam java code, examples

Shallow Copy Deep Copy Java example

Database Connection using NODE JS example