【发布时间】:2013-01-14 20:25:50
【问题描述】:
所以我找到了这段代码here,它有效,它只是在拖动时在图像中引起相当多的抖动(拖动越快,图像抖动越多)。 OP说它没有优化,因为它是一个死帖,我想我会看看这里是否有人可以提供帮助!我也尝试过来自stack 的代码,但我无法让它做任何事情。如果有人对此代码有任何建议,或者更好的解决方案,我很乐意听到!
请注意,我需要拖动的 Jpanel(paintComponent 绘制对象)位于滚动窗格内!
//initial reference point
private Point mouseLocation;
public void mousePressed(MouseEvent evt){
mouseLocation = evt.getPoint();
}
public void mouseDragged(MouseEvent evt){
//current mouse location
Point newLoc = evt.getPoint();
//deltas
int deltaX = newLoc.x-mouseLocation.x;
int deltaY = newLoc.y-mouseLocation.y;
p.setLocation(p.getX()+deltaX,p.getY()+deltaY);
//move the reference point to the current location
this.mouseLocation = newLoc;
}
Here 是一个显示抖动的示例程序!
【问题讨论】:
-
您可以使用插值或高通滤波器..但是您可以将整个代码放在我的计算机上测试抖动吗?
-
6个类700行代码!但是我昨天确实把paintcomponent 放在了here 并且在原帖中另一张海报说它引起了和我一样的问题,所以我不认为它是特定于程序的。即,如果您构建类似的东西,应该会发生抖动。我将致力于创建一个小型测试程序来展示它。
标签: java swing mouseevent draggable