7.15 (Optional) GUI and Graphics Case Study: Drawing Arcs

Using Java’s graphics features, we can create complex drawings that would be more tedious to code line by line. In Figs. 7.257.26, we use arrays and repetition statements to draw a rainbow by using Graphics method fillArc. Drawing arcs in Java is similar to drawing ovals—an arc is simply a section of an oval.

Figure 7.25 begins with the usual import statements for creating drawings (lines 3–5). Lines 10–11 declare and create two new color constants—VIOLET and INDIGO. As you may know, the colors of a rainbow are red, orange, yellow, green, blue, indigo and violet. Java has predefined constants only for the first five colors. Lines 15–17 initialize an array with the colors of the rainbow, ...

Get Java How to Program (early objects), 9/e now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.