Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  "Capturing" the mouse in a Frame or JPanel  (Read 932 times)
0 Members and 2 Guests are viewing this topic.
Offline syndicatedragon

JGO n00b
*

Posts: 9


The Internet!? Is that thing still around?


« on: 2006-03-10 18:08:31 »

When the user puts the mouse cursor in a certain frame, I would like to make the pointer disappear and capture the mouse's movement until the button is released. However, I'd ALSO like the mouse cursor to remain where it was when the user originally started the drag.

I understand how to use MouseListener, MouseMotionListener, and MouseWheelListener, and I'm also pretty sure I can make the cursor disappear. The tricky part seems to be keeping the mouse cursor from moving. How can I do that? Is there some way I can move the cursor to an arbitrary point? It seems like there is probably an interface to do that, but I can't find it...

Thanks.
Offline noblemaster

JGO Ninja
***

Posts: 730
Medals: 6


Age of Conquest makes your day!


« Reply #1 on: 2006-03-10 18:13:24 »

Maybe "java.awt.Robot" helps (set mouse position etc.)?

Making the cursor invisible? Mhh, I know you could set a transparent mouse cursor:
1  
2  
3  
4  
5  
6  
int[] pixels = new int[16 * 16];
Image image = Toolkit.getDefaultToolkit().createImage(
        new MemoryImageSource(16, 16, pixels, 0, 16));
Cursor transparentCursor =
        Toolkit.getDefaultToolkit().createCustomCursor
            (image, new Point(0, 0), "invisiblecursor");

I am not sure if there is a better solution?

Offline swpalmer

JGO Kernel
*****

Posts: 3438
Medals: 4


Where's the Kaboom?


« Reply #2 on: 2006-03-10 18:22:50 »

The tricky part seems to be keeping the mouse cursor from moving. How can I do that? Is there some way I can move the cursor to an arbitrary point?

Yep:

java.awt.Robot


Games published by our own members! Go get 'em!
Offline syndicatedragon

JGO n00b
*

Posts: 9


The Internet!? Is that thing still around?


« Reply #3 on: 2006-03-10 18:28:36 »

I never would have thought to look there .. thanks all.
Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.06 seconds with 17 queries.