Getting mouse position in 1.4.2 ?

I’m using java 1.4.2 and I need to get the mouse position. I’m extending JFrame (MyGame extends JFrame) and while in 1.5 there is getMousePosition() there is nothing like that in 1.4.

Any ideas?

btw. this is for my 4k game, so if there is a simple way to do this then I appreciate that :slight_smile:

use mousemotionlistener? then when there is a mouseMoved event u gcan get the coordinates bij e.getX and e.getY

enableEvents(AWTEvent.MOUSE_EVENT_MASK|AWTEvent.MOUSE_MOTION_EVENT_MASK);

public final void processEvent(AWTEvent e){
MouseEvent mouse = (MouseEvent)e;
_mx=mouse.getX();
_my=mouse.getY();
me=mouse.getModifiersEx();
}

You can also use processEvent for keyboard stuff.

There’s no way to get mouse position when the pointer is outside of java windows in 1.4.2.
If you need to track mouse over java windows only, then tracking the position with
MouseListener would work (check out java.awt.event.MouseMotionAdapter) as suggested by others.

2 oNyx: not the 1.1 stuff, pleeease!

Thanks,
Dmitri

2 oNyx: not the 1.1 stuff, pleeease!

If you can show me something smaller… :wink:

(keep in mind that this is for 4k).

The way onyx pointed out to me works fine for me. thanks :slight_smile:

I see then…

Is there any way of resetting the mouse coordinates in Java? I would like the mouse cursor to be in the center of the screen (or window) in the start of the game. As far as I know, the mouse interrupt sends only coordinates relative to the last mouse position, which is also the way many other interfaces (DirectInput for example) handle the mouse input. So I’d like to know if there’s a way to either reset the coordinates or get the original relative coordinates?

Arzi,

You can set the mouse position (and do some other stuff) using java.awt.Robot. (It’s a class designed for automated GUI tests.)

[quote=“Mr_EEK,post:9,topic:25802”]
Thank you. I didn’t I even know such a class existed :o Seems like my testing is going to a lot easier in the near future :slight_smile: