This site requires JavaScript, please enable it in your browser!
Greenfoot back

Comments for Advanced Mouse Control

Return to Advanced Mouse Control

So it seems that the applet cannot prevent scrolling in-browser even when it is in focus :/ Oh well, mouse code is still useful
davmacdavmac

2011/4/19

It works for me (Firefox 3.6 on linux). The scroll wheel doesn't scroll the web page if the cursor is over the applet.
architscharchitsch

2011/4/19

Amazing..! How did you disable the mouse image?
I still get the page scrolling in Chrome/Firefox/IE and I'm running Windows 7. I'm having trouble finding this on google too, I'll keep searching and see if I can find out anything I should change. Scrolling seems to not lose focus of the Applet, but having focus does not prevent scrolling via the Mouse Wheel (although it does prevent scrolling via the arrow keys) The mouse image is disabled simply by setting the mouse image to a transparent image, using the code davmac provided in the discussion. You can check out the source for any clarifications :) I had some early issues generating the Image object to initialize the cursor, as it kept giving me a security exception, so I eventually resorted to taking an AWTImage object out of a GreenfootImage object and using that :P
davmacdavmac

2011/4/19

Safari on Mac OS X 10.6 also is fine. I haven't looked at the source, but do you consume the mouse events? (I think there is a "consume()" method in the MouseEvent class, or something like that). You may need to consume them to prevent them from getting to the browser window. Worth a try anyway.
A new version of this scenario was uploaded on Tue Apr 19 04:10:04 UTC 2011 Trying to use consume() to prevent scrolling in certain OS's
consume did the trick :D Thanks a bunch!
A new version of this scenario was uploaded on Tue Apr 19 04:37:45 UTC 2011 Made the mouse cursor look more circular, and added in erasing
PiRocksPiRocks

2011/4/19

I'm not sure if you can fix this, but when I make the image too big, or click, my cursor appears.
Thats weird, hmmmm I don't know why that would be happening, as whenever you click, it explicitly *sets* the mouse image to transparent. What OS and browser are you using?
MathManiacMathManiac

2011/4/25

Unique style on making the mouse an actor! I was afraid it will affect my mouse no matter where it is then, but it didn't! Keep up the good work!
PiRocksPiRocks

2011/4/28

Snow Leopard, on safari
Hmmm wierd, no idea why it happens, oh well, at least it doesn't crash or anything like that :P
MathManiacMathManiac

2011/4/30

I meant for it to be anywhere on my laptop screen.
You want the custom mouse cursor to be able to happen even out of the game screen?
MathManiacMathManiac

2011/5/1

No. I don't eant it! I was afraid that might happen.
A new version of this scenario was uploaded on Tue May 24 15:53:07 UTC 2011 Added source code
m.legere1323m.legere1323

2011/5/26

As much as I hate being "that guy" your description says "Enjoy the code and use it in all your Greenfoor Scenarios :D " ...lol, I dont think you intended that, on a different note: Great job here with the scenario!
All fixed :] I tend to write these descriptions pretty quick, and without the luxury of spell-check :P
bournebourne

2011/11/12

I just saw this and got excited to implement scrolling through something such as a page vertically. But I don't see a way to also scroll horizontally. Don't know what that would consist of. On a track pad on my mac I can scroll vertically and horizontally with similar motions. And I believe on a typical mouse, when you press in the scroll wheel you can do the same thing.
bournebourne

2011/11/12

Works vertically nicely though =)
JetLennitJetLennit

2013/4/25

My normal mouse hovers over the dot
JetLennitJetLennit

2013/4/25

Scratch that
Super_HippoSuper_Hippo

2017/6/22

Is there any way to set it back to default? If I want to use it in one world (at least similar as how you have it), but change from that world to another, how to I get the original cursor back (without clicking on reset and set the world manually)?
YehudaYehuda

2017/6/22

To set the cursor back to the default cursor you can use the following (in this scenario where all the imports already exist). panel.setCursor(null);
YehudaYehuda

2017/6/22

I used that line of code in my Scores class in my screenSize scenario where I changed the cursor during loading.
YehudaYehuda

2017/6/22

@Hippo See here: http://docs.oracle.com/javase/8/docs/api/java/awt/Component.html#setCursor-java.awt.Cursor-
Super_HippoSuper_Hippo

2017/6/23

Thank you!