title: Java draw line and pressKey to change color
body: <p>I am trying to draw a line, and change color every time I press 'c' for example. I have 5 boolean variables </p>
  
  <pre><code>boolean redColor = false;   
  boolean blueColor = false; 
  boolean greenColor = false;
  boolean yellowColor = false;
  boolean defaultColor = false;   
  </code></pre>
  
  <p>I have a variable <code>int counter = 0</code> and I use it to increment in function <code>keyPressed(KeyEvent e)</code>. Because I have 5 variables, when counter reach value 6, I reset counter and it starts again from 1, with red color. In <code>paint()</code> method I check those boolean values above, and if they are true, I change color.  </p>
  
  <p>First time , until counter is reseting, I can change colors fine, but after counter reset, my colors will not change. I will write here exactly what it happens:</p>
  
  <pre><code>counter = 1 =&gt; color red   
  counter = 2 =&gt; color blue    
  counter = 3 =&gt; color green   
  counter = 4 =&gt; color yellow    
  counter = 5 =&gt; color black(default)
  counter = 6 =&gt; reset color back to 1   
  </code></pre>
  
  <p>until here everything works fine, but when counter resets and increments again, color is still the same, black, for any value of counter.<br>
  I will write here a part of my code, maybe is not the best way to do it, but I'm new in AWT. I wish to use awt for this. Thank you for reading my post.</p>
  
  <pre><code>public void paint(Graphics g)
      {
          if(mousePressed == true)
          {
              g.drawLine(x1,y1,x2,y2);    
               if(redColor == true)
              {
                  g.setColor(Color.RED);
                  g.drawLine(x1,y1,x2,y2);    
              }
              if(blueColor == true)
              {
                  g.setColor(Color.BLUE);
                  g.drawLine(x1, y1, x2, y2);
              }
              if(greenColor == true)
              {
                  g.setColor(Color.GREEN);
                  g.drawLine(x1, y1, x2, y2);
              }
              if(yellowColor == true)
              {
                  g.setColor(Color.YELLOW);
                  g.drawLine(x1, y1, x2, y2);
              }
              if(defaultColor == true)
              {
                  g.setColor(Color.BLACK);
                  g.drawLine(x1, y1, x2, y2);
              }
          }
      }
  
  
  
  public void keyPressed(KeyEvent e)
  {
          if(e.getKeyChar() == 'c')
          {
              counter ++;
              if(counter == 1)
                  redColor = true;
              if(counter == 2)
                  blueColor = true;
              if(counter == 3)
                  greenColor = true;
              if(counter == 4)
                  yellowColor = true;
              if(counter == 5)
              {
                  defaultColor= true;
              }
              else if(counter == 6)
                  counter = 1;
          }
  }
  </code></pre>