java鼠标事件
在一个鼠标事件的程序中,里面有mouseDragged(MouseEvent e)方法里面有这样的一段代码,代码如下:
public void mouseDragged(MouseEvent e)
{ Component com = null ;
if (e.getSource() instanceof Component )
{ com=(Component)e.getSource();
if (com!=this) //假如不是在窗口中拖动鼠标
move = true ;
e=SwingUtilities.convertMouseEvent(com,e,this); //转移鼠标事件到窗口
if (move)
{ x = e.getX(); //获取鼠标在窗口中的位置坐标
y = e.getY();
int w = com.getSize().width,
h = com.getSize().height;
com.setLocation(x-w/2,y-h/2);
}
}
}
请高手详细分析里面每一段代码的意思同用法作用,谢谢..........