import java.awt.MouseInfo;
// get the mouse's position
Point p = MouseInfo.getPointerInfo().getLocation();
import java.awt.Robot;
// set the mouse position
new Robot().mouseMove( x, y );
PS. DO NOT USE com.sun.* classes (unless you're using Mac, see below).
PS2. Due to a JavaFX issue which seems will be fixed in JavaFX8, you cannot use java.awt classes in Mac, so as pointed out by Alexander Kirov, in Mac you still need to use the com.sun classes like so:
// workaround for Mac only
com.sun.glass.ui.Robot robot =
com.sun.glass.ui.Application.GetApplication().createRobot();
// getPosition of the mouse in Mac
int x = robot.getMouseX();
int y = robot.getMouseY();