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

2014/4/9

Marking a rectangle

Mkheo Mkheo

2014/4/9

#
Hello folks, I am trying to make greenfoot mark a rectangle. I use drawRect method from GreenfootImage. On this code- public void drawRect (int x, int y) { getBackground().setColor(java.awt.color.RED); GreenfootImage.drawRect(x,y,300,400); } it says I'm trying to reference a non-static method from static context Any ideas how can I make this work? -thanks
Zamoht Zamoht

2014/4/9

#
GreenfootImage is a class therefore you want to change the drawing part of your code to the following: getBackground().drawRect(x,y,300,400); This should work if I'm not mistaken.
danpost danpost

2014/4/9

#
You are not drawing the rectangle on the GreenfootImage class. You are wanting to draw it on a GreenfootImage object. The GreenfootImage object you are drawing the rectangle on can be referenced by 'getBackground()'.
1
getBackground().drawRect(x, y, 300, 400);
Mkheo Mkheo

2014/4/9

#
alas it worked, thanks much!
danpost danpost

2014/4/9

#
Mkheo wrote...
alas it worked, thanks much!
YAY! Glad you got it working. Did not mean to be so excited. I was just checking out the yay tag. It does not display "\o/" at the end like the example shows. and the edit tag did not begin the line with "edit: ".
Game/maniac Game/maniac

2014/4/9

#
YAY! TEST
You need to login to post a reply.