Java Reference
In-Depth Information
A commonly-used size for a window is 300 by 300 pixels. You may not want the
flag crammed all the way to the top, so perhaps the upper-left corner of the flag
should be at point (100, 100).
Many flags, such as the flag of Italy, have a width : height ratio of 3 : 2. (You can
often find exact proportions for a particular flag by doing a bit of Internet research
on one of several Flags of the World sites.) For example, if you make the flag 90
pixels wide, then it should be 60 pixels tall. (Why not make it 100 pixels wide?
Then the height would be 100 – 2 / 3ʆ67, which seems more awkward.)
Now you can compute the coordinates of all the important points of the shape:
Step 3 Write Java statements to draw the shapes.
In our example, there are two rectangles and two lines:
Rectangle leftRectangle
= new Rectangle(100, 100, 30, 60);
Rectangle rightRectangle
= new Rectangle(160, 100, 30, 60);
Line2D.Double topLine
= new Line2D.Double(130, 100, 160, 100);
Line2D.Double bottomLine
= new Line2D.Double(130, 160, 160, 160);
If you are more ambitious, then you can express the coordinates in terms of a few
variables. In the case of the flag, we have arbitrarily chosen the top-left corner and
the width. All other coordinates follow from those choices. If you decide to follow
the ambitious approach, then the rectangles and lines are determined as follows:
Search WWH ::




Custom Search