This site requires JavaScript, please enable it in your browser!
Greenfoot back
F-L-Undead
F-L-Undead wrote ...

2011/6/25

Changing the image of the mouse

F-L-Undead F-L-Undead

2011/6/25

#
Hi! I saw some scenarios, where the mouse had no Image... How can I change the Image of the mouse?
Busch2207 Busch2207

2011/6/25

#
First you have to Import these clases:
import greenfoot.core.WorldHandler;
import javax.swing.*;
import java.awt.Cursor;
import java.awt.Point;
import java.awt.Toolkit;
and then use this Method:
     public void ChangeMouseImage(GreenfootImage image, int XClick, int YClick)
    {
        JPanel Panel = WorldHandler.getInstance().getWorldCanvas();
        Cursor Cursor;
        Toolkit Tk = Toolkit.getDefaultToolkit();
        Point CursorPoint= new Point(XClick,YClick);
        Cursor = Tk.createCustomCursor(image.getAwtImage(),CursorPoint,"Somehow");
        Panel.setCursor(Cursor);
    }
It would be better if you call the Method every round... Else there might be some Problems... XClick and YClick is the Location on your Image, where the mouse has to click... The Point (0,0) is the Point (1,1) on the Image. XClick and YClick has to be Positive! The mouse Image has to be 32x32. If not, it will be scaled automatic... If you want to have no Image for the mouse, you just write:
ChangeMouseImage(new GreenfootImage(1,1),0,0);
trias95 trias95

2014/3/30

#
Where abouts in this code do you define the 32 x 32 image to use?
Busch2207 Busch2207

2014/3/30

#
You can define the image wherever you want. That it is scaled to 32x32 is not programmed by me. That's done by the given Toolkit-class from Java.
You need to login to post a reply.