views:

77

answers:

0

hello all , i am painting a curve arrow using java ,

but i cant place to arrow head in the right location

can u help me please

this is what i done so far , icon should be dynamic size , so all should be painted according to the m_size variable

thank you

  public void paintIcon(Component c, Graphics g, int x, int y){
Graphics2D g2 = (Graphics2D)g;
Object hintOriginal = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 

int strokeSize = m_size/6;

Stroke strokeOriginal = g2.getStroke();
g2.setStroke(new BasicStroke(strokeSize ,BasicStroke.CAP_SQUARE,BasicStroke.JOIN_MITER));

g2.drawArc(x+(strokeSize/2), y+(strokeSize/2), m_size-(strokeSize*2), m_size-(strokeSize*2), 45, 180);

g2.setStroke(strokeOriginal);

int arrSize = (m_size/4) + strokeSize;
int[] xArr = new int[3];
int[] yArr = new int[3];

xArr[0] = x;
xArr[1] = x + arrSize;
xArr[2] = x + (arrSize/2);

yArr[0] = y;
yArr[1] = y;
yArr[2] = y - (arrSize/2);

AffineTransform  origXform = g2.getTransform();
AffineTransform newXform  = (AffineTransform)(origXform.clone());

newXform.rotate(Math.toRadians(135) ,x+m_size/2 ,y+m_size/2);
g2.setTransform(newXform);

g2.fillPolygon(xArr ,yArr ,3);

g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, hintOriginal);

}