Forums Register Login

I tried to draw Arrow from Node to another Node object. but its not working

+Pie Number of slices to send: Send
Hi,

i want to draw arrow from source to destination(Point). Souce and destination is Node, node are movable using mouse drag. Already i connected these two node with line usiing drawLine. Now i want replace the line to arrow. I am having two points(point,point1).and i also tried with arrow image.here i am pasted my coding

public void a(Edge edge)
{
Graphics2D g2d = (Graphics2D) _fldchar;
BasicStroke stroke = new BasicStroke(3);
Polygon Poly=new Polygon();
g2d.setStroke(stroke);
Color color = _mthdo(edge);
Point point = new Point(edge.a()._mthif());
point.translate(_fldbyte, _fldtry);

Point point1 = new Point(edge._mthif()._mthif());
point1.translate(_fldbyte, _fldtry);
_fldchar.setColor(Color.red);
Protein protein1 = new Protein(edge._mthif()._mthint(), 0);
Protein protein = new Protein(edge.a()._mthint(), 0);

String type=_types(app,protein,protein1);

int xstart1=point1.x;
int xstop=xstart1+0;

if(type=="first")
{
g2d.setColor(Color.red);
g2d.drawLine(point.x, point.y, point1.x, point1.y);
}
else
{
g2d.setColor(Color.blue);


g2d.drawLine(point.x, point.y, point1.x, point1.y);

g2d.drawImage(origImageblue,point.x,point.y,(point1.x-point.x),(point1.y-point.y),this);
}

//_fldchar.drawLine(point.x, point.y, point1.x, point1.y);
//x1Points=(point.x+2,point.x-2,point.x);

/*

g2d.drawLine(point.x, point.y, point1.x, point1.y);
g2d.drawLine(xstop-4,point.y-4,xstop,point.y);
g2d.drawLine(xstop-4,point.y+4,xstop,point.y);
*/
BasicStroke stroke1 = new BasicStroke(1);
g2d.setStroke(stroke1);
}


Any body can help me, Thanks in Adv

Raja.laxman
+Pie Number of slices to send: Send
Two remarks:
1. a() is a great name for a method. Variable names like 'point' and 'point1' makes it also pretty unreadable for common mortals like me
2. Lack of protein in obese people is risk factor for kidney

Seriously,
what do you mean by "it's not working" ? The arrow is not displayed ?
[ January 09, 2006: Message edited by: Satou kurinosuke ]
+Pie Number of slices to send: Send
Actually edge is contains two nodes(fillOval)(point,point1). variable point is source node contains two value(point.x,point.y) and point1 is destination node(point1.x, point1.y). Using this 4 values i connected two nodes using drawLine.Using this line

(g2d.drawImage(origImageblue,point.x,point.y,(point1.x-point.x),(point1.y-point.y),this);
)i got arrow image between two nodes. but not in connected format.image displayed only in horizontal direction.
+Pie Number of slices to send: Send
Welcome to the beautiful world of mathematics.
You'll have some rotation work to do.
Find the angle between your line and the horizontal axis, and rotate accordingly.
Time is mother nature's way of keeping everything from happening at once. And this is a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1090 times.
Similar Threads
repainting JLabels on a JPanel
How do I layer components on top of each other without blocking lower components?
drawString method only draws first string
JLabel icon redrawing problem
Java 2d graphics
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 03:32:51.