Stop the cursor from leaving the frame/panel?

Im making a simple target game where you shoot targets with the mouse. What I'd like to do is stop the mouse cursor from leaving the panel/frame. I've tried moving the cursor there with the Robot class, but 1) it doesnt lock it directly to the edge, 2) it doesnt stop at the top edge and left edge, 3) the bottom edge results in the cursor being placed in the wrong place and finally, 4) if u move the cursor fast enough it breaks out anyway :(

Hope someone can help,

Thanx.

[495 byte] By [mrenthusiasta] at [2007-9-29 15:00:17]
# 1
You could go fullscreen. Other than that, there isn't a solution (apart from using native code)
Abusea at 2007-7-15 5:58:32 > top of Java-index,Other Topics,Java Game Development...
# 2
Another workaround I just thought of - lock the cursor to the centre of the Frame, and make it invisible.Then render a software cursor where the real cursor should be.You can then lock the cursor to whatever area you want.
Abusea at 2007-7-15 5:58:32 > top of Java-index,Other Topics,Java Game Development...
# 3

You shall have to check the x and y coordinates and see if it gets out of the boundary of the Frame/Panel.And restrict the same.

would you like to show up your Mobile/Java games and code up in this site

http://www.ideas2work.com

Regards,

Istiaque.

http://www.ideas2work.com

guddu_jsa at 2007-7-15 5:58:32 > top of Java-index,Other Topics,Java Game Development...
# 4
Wow nice responses. I have two questions:1) What is native code?2) Is it difficult to make it full screen? I was thinking of doing that but the thought of rescaling everything (i.e. fonts, images etc) made me think otherwise.Thanx,Jon
mrenthusiasta at 2007-7-15 5:58:32 > top of Java-index,Other Topics,Java Game Development...
# 5

> Wow nice responses. I have two questions:

>

> 1) What is native code?

Write the code to capture the mouse in C/C++ (Windows supports capturing the mouse cursor - dunno about linux or solaris), then write a JNI wrapper function so you can call it from within Java.

>

> 2) Is it difficult to make it full screen? I was

> thinking of doing that but the thought of rescaling

> everything (i.e. fonts, images etc) made me think

> otherwise.

Fullscreen is easy, simply graphicsDevice.setFullscreenWindow(window);

Once in fullscreen, you can change the resolution to whatever you like (limited to what is supported by the gfx card ofcourse :p), so you shouldn't have to worry about rescaling gfx 2much.

>

> Thanx,

> Jon

Abusea at 2007-7-15 5:58:32 > top of Java-index,Other Topics,Java Game Development...