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

2011/10/20

Creating a Rectangle

ChrisIsOsmer ChrisIsOsmer

2011/10/20

#
Hi everyone; I'm new to all of this and was looking for some help. Basically I want to call a method that would allow me to create a rectangle (via fillRect())... Could anyone help me out with this code? This is what I have but it doesn't seem to work. Thanks in advance. GreenfootImage image = new GreenfootImage(100, 100); image.fillRect(100, 100, 100, 100); image.setColor(java.awt.Color.RED); setImage(image);
danpost danpost

2011/10/20

#
Try setting the draw color before filling the rectangle in!!!
bourne bourne

2011/10/20

#
You're drawing it off the bounds of you're image. The first 2 parameters are your top left coordinate of the rectangle you are drawing. fillRect(int x, int y, int width, int height) x - the x coordinate of the rectangle to be filled. y - the y coordinate of the rectangle to be filled. width - the width of the rectangle to be filled. height - the height of the rectangle to be filled. Also if you are wanting to have this rectangle be the color red, you should have image.setColor(java.awt.Color.RED); * before image.fillRect(0, 0, 100, 100);
danpost danpost

2011/10/20

#
Thanks bourne! I didn't catch the parameter thing off hand.
ChrisIsOsmer ChrisIsOsmer

2011/10/20

#
Perfect! Thank you guys, I really appreciate it.
actinium actinium

2011/10/22

#
There is a fill() method that requires no parameters.
         
         GreenfootImage image = new  GreenfootImage(100, 100);
         image.setColor(java.awt.Color.RED);
         image.fill();
         setImage(image);
You need to login to post a reply.