title: java drawing a rainbow
body: <p>The program can run but it's not outputting what I want it to output. See, I want 7 concentric arcs which colored as a rainbow. What I'm getting is 7 concentric arcs colored red and yellow. I need the colors in this order:</p>
  
  <p>red, yellow, pink, green, purple, orange, blue</p>
  
  <p>What do I need to add or change? I'm using if else statements to alternate between colors. Which is why it's alternating between red and yellow. I added another set of if else within the other if else statements, I am thinking that I can use them to further alternate.</p>
  
  <p>I'm pretty new to java and loops. I was thinking I could use for, while, if else or do loops for the colors.</p>
  
  <pre><code>import javax.swing.JPanel;
  import java.awt.*;
  public class rainbowpanel extends JPanel
  {
  
  private final int MAX_WIDTH = 300, NUM_RINGS = 7, RING_WIDTH = 20;
  
  
  
  public rainbowpanel ()
  {
  setBackground (Color.white);
  setPreferredSize (new Dimension(300,300));
  }
  
  
  
  
      public void paintComponent (Graphics page)
  
      {
          super.paintComponent (page);
          int x = 0, y = 0, diameter = MAX_WIDTH;
          page.setColor (Color.yellow);
       for (int count = 0; count &lt; NUM_RINGS; count++)
  
  
          {
              if (page.getColor() == Color.yellow) // alternate colors
              page.setColor (Color.red);
              else
              page.setColor (Color.yellow);
              page.fillArc (x, y, diameter, diameter, 0, 180);
  
  
  
  
              diameter -= (2 * RING_WIDTH);
              x += RING_WIDTH;
              y += RING_WIDTH;
              }
  
  
  
              {
              if (page.getColor() == Color.yellow) // alternate colors
                  page.setColor (Color.pink);
              else
                  page.setColor (Color.orange);
                     page.fillArc (x, y, diameter, diameter, 0, 180);
  
  
  
              //diameter -= (2 * RING_WIDTH);
              //x += RING_WIDTH;
              //y += RING_WIDTH;
  }
  
  
  
  
              page.setColor (Color.white);
              page.fillArc (x, y, diameter, diameter, 0, 180);
  }
  }
  </code></pre>
  
  <p>You have to run it from this file:</p>
  
  <pre><code>import javax.swing.JFrame;
  public class rainbow
  
  {
  
  public static void main (String[] args)
  {
  JFrame frame = new JFrame ("Rainbow");
  frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
  
  
  rainbowpanel panel = new rainbowpanel();
  frame.getContentPane().add(panel);
  frame.pack();
  frame.setVisible(true);
  }
  }
  </code></pre>