public static void addEvent(Component l){
l.addMouseListener(
new MouseAdapter(){
public void mousePressed(MouseEvent e){ x=e.getX();y=e.getY(); } });
l.addMouseMotionListener(new MouseMotionListener(){ public void mouseDragged(MouseEvent e) { JLabel l = (JLabel)e.getSource();
l.setLocation(l.getX()+e.getX()-x,l.getY()+e.getY()-y);
}
public void mouseMoved(MouseEvent e) {} });
}
javaGUI界面简单实现鼠标拖动图片移动函数
最新推荐文章于 2024-07-24 09:54:20 发布