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

2013/11/29

Giving a cell a certain color?

Aaron91 Aaron91

2013/11/29

#
Hello, Iam new to Java and Greenfoot, and i want to create my own World. Can anyone tell me how i can give a certain cell a color? I got a 8x8 field, and i just want 3x8 to have the color Blue. How can i fill these specific cells?
danpost danpost

2013/11/30

#
getBackground().setColor(java.awt.Color.blue);
getBackground().fillRect(/* startX, startY, lenX, lenY */);
'getBackground' will return the image for the entire background (regardless of cells) and all argument values ('startX', 'startY', 'lenX', and 'lenY') use pixel as the unit of measure. Therefore, 'lenX' will equal three times the cellsize ('3*getCellSize()')and 'lenY' will equal eight times the cellsize ('8*getCellSize()').
Aaron91 Aaron91

2013/11/30

#
you sir.. are a savior..
You need to login to post a reply.