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

2021/5/9

Is it possible to make the mouse cursor hidden or change the image of the mouse cursor?

Jayyhk Jayyhk

2021/5/9

#
I don't think this is possible because it involves changing the mouse cursor of the display. If it is possible, how can I do it? Thanks in advance.
RcCookie RcCookie

2021/5/9

#
It is, you may want to do some research, BUT it ain’t work on the website. If you are interested, you may want to search on google for „java change cursor image“
Jayyhk Jayyhk

2021/5/9

#
got it will do
Jayyhk Jayyhk

2021/5/9

#
After a bit of searching, I came across this method.
public void changeCursor() 
    {
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Image image = toolkit.getImage("nothing.png");
        Point point = new Point(0,0);
        Cursor cursor = toolkit.createCustomCursor(image,point,"Cursor");
        setCursor(cursor);
    }
The only problem is, where exactly do I put this method in greenfoot?
danpost danpost

2021/5/9

#
You cannot just call setCursor on "this" -- being a World or Actor object. The setCursor method is a java.awt.Component method and must be called on a Component object. In the more recent versions of greenfoot, since greenfoot.core.WorldHandler no longer has a "canvas" field nor a getCanvas method, setting a new cursor to the window seems out of reach.
Jayyhk Jayyhk

2021/5/9

#
ah I understand, thanks for informing me.
RcCookie RcCookie

2021/5/9

#
You may still be able to access these information, using reflection (accessing any field by name, also private ones). I’ll take a look at that soon
You need to login to post a reply.