7.17 (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.

 1   // Fig. 7.25: DrawRainbow.java 2   // Drawing a rainbow using arcs and an array of colors. 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 violet10      private final static Color VIOLET = new Color(128, 0, 128);11      private ...

Get Java™ How To Program (Early Objects), Tenth Edition 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.