public void mouseDragged(MouseEvent e) {
JLabel source = (JLabel)e.getSource();
Point imgPoint = source.getLocation();
Point point = e.getPoint();
source.setLocation(imgPoint.x+point.x-pressPoint.x,imgPoint.y+point.y-pressPoint.y);
//pressPoint为保存拖放标签时的起始坐标
/*this.x = e.getX();
this.y = e.getY();
targets.setLocation(x,y);
*/
}
此代码的作用是让组件跟着鼠标拖动,而注释中的代码是我自己的思路,但显然是实现不了的,是因为getPoint和getLocation有区别吗?如果没有区别那么请问为什么实现不了而要用那段代码呢?谢谢各位