0

Picture: http://gyazo.com/e3bd39a4a967f4cd331f731fd6920702

The red cross on the picture represents the mouse position.

When I drag my box it keeps going grabbing the box in the upper left corner. How can I change this piece of code so that it will grab the box from the position where the mouse started to grab the box.

Here is my code: (GraphicsAlignment.settings = the point of the box) (Size of the grabable area 200x20)

        if (Mouse.isDragging) {
        Point pressed = Mouse.pressed;
        if ((pressed.x > GraphicsAlignment.settings.x && pressed.x < GraphicsAlignment.settings.x + 200
                && pressed.y > GraphicsAlignment.settings.y && pressed.y < GraphicsAlignment.settings.y + 20)
                || isEnabled) {
            GraphicsAlignment.settings.x = Mouse.dragged.x;
            GraphicsAlignment.settings.y = Mouse.dragged.y;
            Boot.getDisplayApplet().setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
            isEnabled = true;
        } else {
            Boot.getDisplayApplet().setCursor(Cursor.getDefaultCursor());
        }
    } else {
        isEnabled = false;
        Boot.getDisplayApplet().setCursor(Cursor.getDefaultCursor());
    }

1 Answers1

0

what class is (Mouse) and what is value of (Mouse.Pressed)? You should get the current Mouse x and Mouse Y by adding a listener http://javalessons.com/cgi-bin/fun/java-programming.cgi?1cd=mev&sid=ao789&j2ee=jsp

Then can get the X Y

tgkprog
  • 4,493
  • 4
  • 41
  • 70