-3

I'm doing an assignment. This is the first part of the assignment:

Drawing a single brick

These are the steps to draw a brick:

  1. Construct a new Rectangle object.

  2. Set the position of your rectangle according to the coordinates that were passed in as parameters.

  3. Change the size of the rectangle to be the proper size of a brick. There are two fields defined for you, one is called bWidth and the other is called bHeight and these are initialised wth values already as the width and height of a brick.

Note: Do not change the values of bWidth or bHeight in this task. Leave them as they are. (bWidth = 54) (bHeight = 16)

  1. Add the rectangle to the ArrayList called bricks using the add method.

  2. Last of all, make the rectangle visible

This is my current code:

private void drawBrick(int startX, int startY){

    Rectangle brick1 = new Rectangle();

    startX = 54;
    startY = 16;

    brick1.setPosition(startX, startY);

    bricks = new ArrayList<Rectangle>();
    bricks.add(brick1);


    brick1.makeVisible();

}

But everytime I construct the object and call the draw method, nothing appears. What did I do wrong?

J.Doe
  • 47
  • 1
  • 6

1 Answers1

0

Assuming nothing else is wrong, you are missing setSize: you have a Rectangle at the appropriate position, but it is invisible because both its width and height are the default 0.

(I also do not know about makeVisible method.)

Amadan
  • 191,408
  • 23
  • 240
  • 301
  • 1
    Unless `Rectangle` is a custom class, `makeVisible` is not a method (source: [Java 8 API](https://docs.oracle.com/javase/8/docs/api/java/awt/Rectangle.html)). – Eli Sadoff Nov 07 '16 at 01:31
  • @EliSadoff: Yup, you worded it better than I did. – Amadan Nov 07 '16 at 01:31