开发者

Drawing/plot is not continuous (mouse events involved)

I'm having issues with a java class project. The first step consist in drawing a pattern, so I thought well, this can't be hard. And it isn't, but there one thing that really bothers me. First, check the screenshot below :

Screenshot

My problem is that this was done without releasing the mouse, so the drawing should be continuous. Instead of this, there's holes in it. I'm thinking this is related to the way mouse events are transmitted, But I have no idea how to tweak this.

The drawing zone is a JPanel. There is a set of Points that is used to paint the container on mouse events. Pressing add the first point, dragging the others, rel开发者_如何学编程eased clear the drawing zone.

Hope I was specific enough. Thanks for your time!

edit : Forgot the code. http://pastebin.com/RyXiGsvm


StanislavL's right that mouseMove/mouseDrag events are not generated for every pixel you move the mouse cursor over. Why don't you want to use lines? If the issue is that the result is ugly and jagged, you might consider using cubic splines instead. GeneralPath.curveTo provides an easy way to do this. If getting the control points right is a pain, you can also use GeneralPath.quadTo; this is a quadratic approximation that won't look quite as good, but you can easily just pass in the last three points from mouseDrags.


I guess you store mouse points obtained in mouseDrag processing. Mouse drag happens from after some time interval so if you move mouse relatively fast you just got points. TO drai it you can use drawLine() passing pairs of point. So you'll have lines.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜