【发布时间】:2014-06-03 11:09:26
【问题描述】:
我想在 JFrame 中创建一个简单的画笔。为此,我创建了一个 BufferedImage,当鼠标被拖动时,我刚刚重新绘制它并设置为图像更改。
问题是,如果我拖动鼠标太快,则不会绘制所有点。 它看起来像虚线。
这是我更新图像的代码:
public void mouseDragged(MouseEvent evt)
{
int x = evt.getX();
int y = evt.getY();
if(eraser == false)
this.Dice(x, y);
else
this.Eraser(x, y);
g = (Graphics2D) this.getGraphics();
g.drawImage(image, positionX, positionY, null);
g.dispose();
}
在 Dice 和 Eraser 方法中,我对 图像 进行了更改(我设置了像素)。 我真的不知道如何修复它。
感谢您的帮助。
【问题讨论】:
-
不要使用
getGraphics,覆盖paintComponent并在那里绘制图像,然后调用repaint
标签: java refresh draw bufferedimage mouse-listeners