通过实现mouseAdapter可以实现组件的拖拉操作public void mouseDragged(MouseEvent me) {
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
Container parent = getParent();
int w = parent.getWidth();
int h = parent.getHeight();
int x = getX()+me.getX()-focusPoint.x;
int y = getY()+me.getY()-focusPoint.y; if(x+getWidth() > w) x = w-getWidth();
if(x<0) x=0;
if(y+getHeight() > h) y = h-getHeight();
if(y<0) y=0;
setLocation(x,y);
//MyNode.Points.put(this,new Point(x,y));
((MyNode)me.getSource()).showInfo();
parent.repaint();
parent = null;
}
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
Container parent = getParent();
int w = parent.getWidth();
int h = parent.getHeight();
int x = getX()+me.getX()-focusPoint.x;
int y = getY()+me.getY()-focusPoint.y; if(x+getWidth() > w) x = w-getWidth();
if(x<0) x=0;
if(y+getHeight() > h) y = h-getHeight();
if(y<0) y=0;
setLocation(x,y);
//MyNode.Points.put(this,new Point(x,y));
((MyNode)me.getSource()).showInfo();
parent.repaint();
parent = null;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货