-1

I understand this code here. The point of origin is 0,0 or top left of the JFrame and the width of the rectangle is 9 and height covers from bottom to top.

Rectangle left = new Rectangle(0,0,WIDTH/9,HEIGHT);

But I don't quite understand this. What is the point of origin here? Is 9 being multiplied by 8 or is it saying the measurement is 9 by 8? What is the purpose of the multiplication sign?

Rectangle right = new Rectangle((WIDTH/9)*8,0,WIDTH/9,HEIGHT);
Adam Zalcman
  • 26,643
  • 4
  • 71
  • 92
Martin Marino
  • 375
  • 2
  • 5
  • 14

4 Answers4

0

What is the purpose of the multiplication sign?

The x origin of the rectangle is 8/9 of the way across the JFrame. It's right justified (I assume).

Gilbert Le Blanc
  • 50,182
  • 6
  • 67
  • 111
0
Rectangle right = new Rectangle( (WIDTH/9)*8, 0, WIDTH/9, HEIGHT);

This means that the x origin is real 9/8th of the WIDTH. And its width is 1/9th WIDTH variable. Looks like this would move the rectangle horizontally.

mprivat
  • 21,582
  • 4
  • 54
  • 64
0

Without seeing the whole code it's hard to know, but I'd assume that WIDTH is the total width of whatever will contain the two rectangles. In that case, you'll end up with two rectangles that themselves have a width one-ninth of the total width, and occupy the left and right sides of the container.

Since the co-ordinates are the top left corner of the rectangle, to make the one-ninth width rectangle occupy the right side of the container, the x co-ordinate needs to be eight-ninths of the total width, which is what (WIDTH/9)*8 calculates.

Anthony Grist
  • 38,173
  • 8
  • 62
  • 76
0

a bit of reworking of the values gives us

Rectangle right = new Rectangle(WIDTH-(WIDTH/9),0,WIDTH/9,HEIGHT);

this means that the right side of right falls on WIDTH

ratchet freak
  • 47,288
  • 5
  • 68
  • 106