日期:2014-05-20  浏览次数:20624 次

java无窗体鼠标流畅拖动怎么实现?
本帖最后由 cxiyue 于 2013-06-10 00:28:26 编辑

this.addMouseMotionListener(new MouseAdapter() {

  @Override
  public void mouseDragged(MouseEvent e) {
    // TODO Auto-generated method stub
    该怎么写
  }
});
无窗体拖动 Java

------解决方案--------------------
this.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
isDraging = true;
xx = e.getX();
yy = e.getY();
}

public void mouseReleased(MouseEvent e) {
isDraging = false;
}
});
this.addMouseMotionListener(new MouseMotionAdapter() {

public void mouseDragged(MouseEvent e) {
if (isDraging) {
int left = getLocation().x;
int top = getLocation().y;
setLocation(left + e.getX() - xx, top + e.getY() - yy);
}
}

});