Draw a line connecting two rectangles

I create my own class diagram application in Swing / AWT, but I settled on this function:

  • I want to draw a line between the selected rectangle of the class and the target rectangle of the class, but there is a function in the line that occurs when I move one of the rectangles, the connecting line is bent in a direct way, following the moving rectangle, I hope that the following picture will demonstrate that I want to achieve: alt text

General guidance or sample code is welcome.

+3
source share
4 answers

I do not know Java, but the steps you could follow are as follows:

  • Find the middle of each line of rectangles (should be easy, just avarage x1 + x2 and y1 + y2)
  • , , , .
  • , xa, ya ( , ), . , , .
  • xb, yb ( ). , xa-xb ya-yb ( , ). ( ?), , , xa, ya xa, yb xa, ya xb, ya, , .
  • , , . , . , , , .

, , , .

+4

observer . , , "" . , , 2 .

+1

"ConnectionLine" . ( uml), . , , ), "LineSegment". , , .

" " d (^_^) b

-1

Source: https://habr.com/ru/post/1784529/


All Articles