RevMen
October 5, 2011, 1:30am
1
This draws a line:
DrawLine dLine = new DrawLine();
dLine.setEndArrow(ArrowStyle.BLOCK);
dLine.setStartPoint(new Point(x1,y1));
dLine.setEndPoint(new Point(x2,y2));
dLine.setDrawPane(myDrawPane);
dLine.draw();
But no arrowhead. Is it just not implemented yet? Or am I doing something wrong?
edit: I see that I can draw an OPEN arrow on a DrawLinePath , but that seems to be the only thing working. So I guess the other arrows just haven’t been implemented yet.
RevMen
October 5, 2011, 3:46am
2
If anyone needs to draw an arrow, as I do, here’s a simple class that will draw a line with an arrowhead between two points on a specified DrawPane .
public class DrawArrow extends DrawGroup {
private DrawLine main;
private DrawLine tick1;
private DrawLine tick2;
private int thickness = 5;
private String color = "black";
//length of tick marks
private int barb = 15;
//angle of tick marks
private double phi = Math.toRadians(40);
public DrawArrow(Point s, Point f,DrawPane dp){
this.setDrawPane(dp);
Draw(s,f);
}
public void Draw(Point s, Point f){
main = new DrawLine();
main.setStartPoint(s);
main.setEndPoint(f);
main.setDrawGroup(this);
main.setLineColor(color);
main.setLineWidth(thickness);
main.draw();
double dx = Double.valueOf(f.getX() - s.getX());
double dy = Double.valueOf(f.getY() - s.getY());
double theta = Math.atan2(dy, dx);
double rho = theta + phi;
Point t1 = new Point((int)Math.round(f.getX() - barb*Math.cos(rho)),(int)Math.round(f.getY() - barb*Math.sin(rho)));
tick1 = new DrawLine();
tick1.setStartPoint(f);
tick1.setEndPoint(t1);
tick1.setDrawGroup(this);
tick1.setLineColor(color);
tick1.setLineWidth(thickness);
tick1.draw();
rho = theta - phi;
Point t2 = new Point((int)Math.round(f.getX() - barb*Math.cos(rho)),(int)Math.round(f.getY() - barb*Math.sin(rho)));
tick2 = new DrawLine();
tick2.setStartPoint(f);
tick2.setEndPoint(t2);
tick2.setDrawGroup(this);
tick2.setLineColor(color);
tick2.setLineWidth(thickness);
tick2.draw();
}
public void MoveArrow(Point s, Point f){
main.erase();
tick1.erase();
tick2.erase();
Draw(s,f);
}
}