I'm struggling to find a way to get the X and Y co-ordinates of the mouse, as I want to display them on the screen, but I'm getting an error with the showText. I'm probably missing something obvious, because I haven't used Greenfoot to code in two years. Can anyone help?
My code:
I'm not sure if I need to add anything into another class or subclass, so I haven't yet.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | import greenfoot.*; public class MouseInfo extends java.lang.Object { public int getX; public int getY; public MouseInfo() { } public void act() { location(); //location code } public void location() { showText( "X: " +getX, 50 , 50 ); showText( "Y: " +getY, 100 , 50 ); } } |