private class MouseMotionProcess extends MouseMotionAdapter {
public void mouseDragged(MouseEvent e) { Container container = jButton1.getParent(); int w = container.getWidth(); int h = container.getHeight();
int x = jButton1.getX() + e.getX() - focusx; int y = jButton1.getY() + e.getY() - focusy;
if (x + jButton1.getWidth() > w) { x = w - jButton1.getWidth(); } if (y + jButton1.getHeight() > h) { y = h - jButton1.getHeight(); } if (x < 0) { x = 0; } if (y < 0) { y = 0; }