• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Raja laxman
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Raja laxman
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!