Java Application : mouseDragged Event isn't Executed Often Enough

谁说胖子不能爱 提交于 2019-12-23 01:52:08

问题


Is there a way to make the mouseDragged Event be called more Often ( In my Case, Drawing a Color? I need it for Smooth Drawing, because right now, if you move too fast, it doesn't Draw All my Path. Also, I have an 2D Array Storing the Color of the Pixel, so that's also Problematic if I try to solve by problem by another Way, that's why I thought Increasing the mouseDragged Frequency would be the Best thing to Do

Thanks


回答1:


If you want smooth drawing, you'd likely have to interpolate the data yourself. If you get an event at (3,3) and another at (10,10) you can figure the slope between the two, and iterate through the logical points that the mouse must have been dragged to get from (3,3) to (10,10)

I don't know of a way to force mouseDragged to update faster, and if, for instance the system was under high load, or someone used a touch screen, you might get huge jumps anyhow.




回答2:


If you are drawing ovals to as color lines, change to lines:

ArrayList<> colors;

mousepressed(Event e) {
    startPoint = e.getPoint();
}

mousedragged(Event e) {
    colors.add(new Color(startPoint, e.getPoint);
    startPoint = e.getPoint();
}

class Color() {

    Color(Point start, Point end) {
        // ...
    }

    paint(Graphics g) {
        g.drawLine(start, end);
    }
}


来源:https://stackoverflow.com/questions/6886878/java-application-mousedragged-event-isnt-executed-often-enough

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!