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

2018/7/11

How to add border to a rectangle/square?

ImanMalhi ImanMalhi

2018/7/11

#
Here is my code for a square:
public Square(Color color)
    {
        GreenfootImage img;
        img = new GreenfootImage(90,90);
        img.setColor(Color.BLACK);
        img.drawRect(0,0,90,90);
        img.setColor(color);
        img.fill();
        setImage(img);
    }
How would I add a border around the square? Thanks~
danpost danpost

2018/7/11

#
ImanMalhi wrote...
Here is my code for a square: << Code Omitted >> How would I add a border around the square?
Set a different color to the image and use the drawRect method to draw the border.
ImanMalhi ImanMalhi

4 days ago

#
I don't understand. Also here's some context, I'm coding the game Light's Out (http://www.logicgamesonline.com/lightsout/). I'm trying to make a grid and I want to add a border to the squares so the user can click on them w/o any trouble. Here's my code for adding the squares.
public void displayGrid()
    {
        Square sq = new Square(Color.YELLOW);
      
        
        for (int i=0;i<Constant.SIZE;i++)
        {
            for(int j=0;j<Constant.SIZE;j++)
            {
                if(on)
                {
                    sq=new Square(Color.YELLOW);
                }
                else
                {
                    sq=new Square(Color.BLACK);
                }
                addObject(sq,i,j);
            }

        }
Right now this leaves a screen with all black squares (which is what I want). But since there's no border, it looks like an all-black screen. Anyways, I couldn't figure out what you meant. Could you show me an example. Sorry - I'm new to greenfoot.
danpost danpost

3 days ago

#
I apparently mistook what you had in your original code. Reverse the order -- fill first, then draw the rectangle.
You need to login to post a reply.