Java Application : mouseDragged Event isn't Executed Often Enough

大兔子大兔子 提交于 2019-12-06 16:11:02

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.

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