画一条线连接两个矩形
我正在 Swing/AWT 中制作自己的类图应用程序,但我停在了这个功能上:
- 我想在已选择的类矩形和目标类矩形之间画一条线,但线有一个功能,每当我移动一个线时在矩形中,连接它们的线随着移动的矩形以直线方式弯曲,我希望下图展示了我想要实现的目标:
非常感谢一般指南或示例代码
I am making my own class diagram app in Swing/AWT but i stopped at this functionality:
- I want to draw a line between the Class rectangle that already selected and to the target Class rectangle, but line has a feature which is whenever i move one of the rectangles the line that join them get bend in a straight fashion following the moving rectangle , i hope the following picture demonstrate what i want to achieve:
A general guideline or a sample code is highly appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不懂 Java,但您可以遵循以下步骤:
对于实现,您可以构建一个线类,该线类使用观察者模式来侦听它所遵循的两个矩形,因此只要其中一个矩形移动或调整大小,它就可以自我更新。
I don't know Java, but the steps you could follow are these:
For the implementation you could build a line class that uses the observer pattern to listen to the two rectangles it follows, so it can update itself whenever one of them moves or resizes.
http://java-sl.com/connector.html
希望这有帮助。
http://java-sl.com/connector.html
Hope this helps.
尝试使用 观察者 模式。所有与移动物体连接的线都应收到该物体的新位置通知并正确“弯曲”。当然,首先实现一些连接两个对象的逻辑。
Try with observer pattern. All lines that are connected with a moving object should be notified with new position of the object and 'bent' properly. Of course, first implement some logic that will connect 2 objects.
尝试创建一个名为“ConnectingLine”或类似名称的类。这个类将有几个线段(这是 dia 中这些线部分的名称,这是目前我最喜欢的 uml 建模工具),这些线段将被一一计算。当然,您将有一个单独的类;)可能称为“LineSegment”。我认为这应该使您可以更轻松地执行执行此任务所需的数学计算。
这也可以使分段“自动路由或不自动路由”变得容易 d(^_^)b
try creating a class named "ConnectingLine" or similar. this class will then have several segments (that's the name of these line parts in dia, which is currently my favorite uml modeling tool) which will be calculated one by one. you'll have a sepaparate class for this of course ;) called maybe "LineSegment". i think this should make it easier for you to perform the mathematical calculations required to perform this task.
this could also enable making segments "auto routed or not" easy d(^_^)b