#Pointer position is based on the location of the frame on the monitor?

1 messages · Page 1 of 1 (latest)

barren lance
#

So I am making a little game and have come across this weird bug where the position of the mouse is based on the position of the window on my monitor. To get the X and Y of the mouse I just use MouseEvent.getXOnScreen() and MouseEvent.getYOnScreen(). I have attached a video to make this more clear. Does anyone know how to fix this?

ionic runeBOT
#

<@&987246399047479336> please have a look, thanks.

ionic runeBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

barren lance
#

This is the code that I am referring to: ```@Override
public void mouseDragged(MouseEvent e) {
mousePosition.setXY((int) e.getXOnScreen(), (int) e.getYOnScreen());
}

@Override
public void mouseMoved(MouseEvent e) {
    mousePosition.setXY((int) e.getXOnScreen(), (int) e.getYOnScreen());
}```
ionic runeBOT
unkempt talon
#

instead of getXOnScreen/getYOnScreen

#

there should be a method like getX

#

and getY

barren lance
#

I tried that aswell but I got the same result

unkempt talon
#

shouldnt be the case

#

getXOnScreen

#

gives you the x location on the whole screen

#

and getX will give you the x of the component I think

barren lance
#

Wait sorry, when I use getX and getY the position isn't based on the position of the window anymore but the pointer is still offsetted too much on the Y axis.

#

I think this is because of the window bar on the top but I'm not sure.

unkempt talon
#

yeah could be

#

but it seems like you want to replace the pointer when using the mouse over your window right?

barren lance
#

I just need to check if the mouse clicks on objects on the screen

#

I'm not trying to detect the cursor.

unkempt talon
#

buttons etc got methods to add code that runs when you click on a component etc

barren lance
#

I use a Rectangle as a button and I'm trying to check when the mouse is clicked on the rectangle

unkempt talon
#

why though?
why not use button instead of rectangle

barren lance
barren lance
unkempt talon
#

or just use a Button

#

its literally created for smth like that