created 01/22/00; revised 12/10/10, 06/27/2016
For these exercises, use getWidth()
and getHeight()
rather than hard-coding width and height into your code.
Write an program that displays four circles in a square drawing area. Each circle is centered in one of the four quadrants of the drawing area and each circle is a different color.
Click here to go back to the main menu.
Write an program that displays a set of three concentric filled circles of different colors centered in the the program's drawing area.
Click here to go back to the main menu.
Draw a quadrilateral that connects the center points of the four edges of the program.
You might want a filled quadrilateral instead of just lines. To do that, use
fillPolygon(int[] xPoints, int[] yPoints, int nPoints)
and
drawPolygon(int[] xPoints, int[] yPoints, int nPoints)
where X coordinates of each vertex are put in xPoints
and the corresponding Y coordinates are in Ypoints
.
The number of vertices are in nPoints
.
For example, a triangle that fills the upper left half of a 100 by 200 panel could be drawn with
int[] xPoints = [ 0, 0, 199]; int[] yPoints = [ 99, 0, 0 ]; gr.fillPolygon( xPoints, yPoints, 3 );
Click here to go back to the main menu.
Draw a large asterisk * in the center of the the program's drawing area by drawing four lines that intersect in the center. (Harder: draw the * using five short lines that radiate from the center of the program.)
Click here to go back to the main menu.
Draw five nested rectangles of various colors.
Click here to go back to the main menu.
Draw N nested rectangles, where each rectangle is spaced 5 pixels from its neighbors, no matter what the size of the program. N is an integer variable that depends on the size of the program. The larger the program, the more rectangles are drawn. You will need to use a loop for this.
Click here to go back to the main menu.
End of the Exercises