sclass WindowDragger extends MouseAdapter { MouseEvent mouseDownEvent; JComponent src; Pt rel; Window window; *(MouseEvent *mouseDownEvent) { if (mouseDownEvent == null) ret; src = optCast JComponent(mouseDownEvent.getComponent()); if (src == null) ret; window = getWindow(src); if (window == null) ret; rel = pt( mouseDownEvent.getXOnScreen()-window.getX(), mouseDownEvent.getYOnScreen()-window.getY()); addMouseAndMotionListener(src, this); } public void mouseDragged(MouseEvent e) { updatePosition(e); } public void mouseReleased(MouseEvent e) { if (e.getButton() != mouseDownEvent.getButton()) ret; updatePosition(e); removeMouseAdapter(src, this); dragDone(); } void updatePosition(MouseEvent e) { window.setLocation( e.getXOnScreen()-rel.x, e.getYOnScreen()-rel.y); } void dragDone {} }