Graphic Java

The student could draw squares and rectangles using the drawLine method, but Java provides a method dedicated to drawing rectangles to make this task a bit easier for the programmer. Here's how the method is called:

This example will draw a square with sides 50 units long with the upper-left corner at (20,30). That is, the upper-left corner will be 20 units to the right of the left side of the applet area and 30 units down from the top of the applet area.

This example will create a rectangle 30 units tall and 100 units wide with its upper-left corner at (50,40):

   g.drawRect(50, 40, 100, 30);
EXAMPLE: This applet is an approximation of what the student will be expected to create. No code will be offered since the student will need to experiment with the use of the drawRect method to successfully complete this activity.

The student will recreate the applet displayed on this page using the colors shown and placing the rectangles as shown. It will help a lot to draw this out on paper and figure out appropriate coordinates before attempting to write the code to produce this image.