O'Reilly logo

Java™ How to Program, Seventh Edition by P. J. Deitel - Deitel & Associates, Inc., H. M. Deitel - Deitel & Associates, Inc.

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

7.13. (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 Fig. 7.22 and Fig. 7.23, 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.22. Drawing a rainbow using arcs and an array of colors.
 1 // Fig. 7.22: DrawRainbow.java
 2 // Demonstrates using colors in an array.
 3 import java.awt.Color;
 4 import java.awt.Graphics;
 5 import javax.swing.JPanel;
 6
 7 public class DrawRainbow extends JPanel
 8 {
 9    // Define indigo and violet
10    final Color VIOLET = new Color( 128, 0, 128 );
11    final Color INDIGO ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required