Re: drawing arrows...



> I'm a newcomer to Java programming. I need to draw some arrows in a
> window. Drawing lines is no problem, but I don't see an arrow-drawing
> capability in the Graphics2D class. It seems that this would be a
> common need - anyone ever see any publicly available classes with this
> capability?

you can define shape of appropriate form and then use Graphics2D methods
fill(Shape) and draw(Shape)
in com.imagero.gui.swing.Shapes.java I defined some basic shapes (triangles,
arrows, circles, rectangles, twin and quad arrows).
There are also an applet which uses it:
http://jgui.imagero.com/examples/JShape/

here is an arrow looking at north:

public static Area createArrow(int width, int height, int length, int
direction) {
int arrowStart = Math.abs(length - height);
int lineWidth = width / 3;
return new Area(new Polygon(
new int[]{lineWidth, lineWidth, 0, width / 2, width,
width - lineWidth, width - lineWidth},
new int[]{0, arrowStart, arrowStart, length,
arrowStart, arrowStart, 0},
7));
}
you can use AffineTransforn tomake it looking at any direction.

--
Andrey Kuznetsov
http://uio.imagero.com Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities


.



Relevant Pages