We can even omit the listener variable and insert the code that uses the anonymous class directly as the parameter:
component.addMouseListener( new MouseAdapter() { public void mousePressed(MouseEvent event) { int x = event.getX(); int y = event.getY(); component.moveTo(x, y); } });