开发者

How do I move a painted line in Java,using my mouse? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I hava a project which will look like similar to Paint program. Here, I'm supposed to draw lines with start and end points and then I need to be able to move these lines by simply dragging my mouse on them. I draw the lines using the drawLine method of Java. The problem is, I have no idea how to move the开发者_如何转开发se lines :(

Please help me if you have an idea on this, Thanks.


You need to add some sort of ActionListener and detect when the user clicks a line on the screen. Then you need to monitor the mouse movement; and rePaint() the line.


i think you should clear the canvas on the mouseMove event with fillRect(int x, int y, int width, int height) on the graphics objet , and within the event get the mouse location.

 public void mouseMoved( MouseEvent e ) {  // called during motion when no buttons are down
      mx = e.getX();
      my = e.getY();

      repaint();
   }

then in your paint method you should draw the line using mx, my coordinates aproprietly

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜