title: Action on touching color
body: <p>I made a flappy birds game and is working well till now. But now I am stuck with a problem, I want the game to start all over when the the bird touches the color of the wall. Here is the source code. By the way, I think this may not be properly formatted. As I am a newbie, can you also suggest how to formath this code properly? Thank you.</p>
  
  <pre><code>import java.awt.Color;
  import java.awt.Font;
  import java.awt.Graphics;
  import java.awt.Rectangle;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.awt.event.KeyListener;
  import java.util.ArrayList;
  import java.util.Random;
  
  import javax.swing.JFrame;
  import javax.swing.JPanel;
  import javax.swing.Timer;
  
  public class FlappyBirds extends JPanel implements ActionListener,KeyListener {
  
      public int WIDTH=800,HEIGHT=800,x=WIDTH/2-10,y=HEIGHT/2-10 , gravity=0,       ticks=0;
      public static FlappyBirds flappy;
      public boolean jump;
      public boolean run=true;
      public ArrayList&lt;Rectangle&gt;walls;
  
      public Random generator;
  
      public FlappyBirds(){
          Timer t=new Timer(10,this);
          JFrame window=new JFrame("Flappy Birds");
          window.setSize(WIDTH ,HEIGHT);
          window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          window.add(this);
          window.setVisible(true);
          window.addKeyListener(this);
          walls=new ArrayList&lt;Rectangle&gt;();
  
          generator=new Random();
          addWall(true);
          addWall(true);
  
  
          t.start();
      }
  
      public static void main(String[] args) {
          flappy=new FlappyBirds();
      }
  
      @Override
      public void paintComponent(Graphics g){
  
          super.paintComponent(g);
          g.setColor(new Color(0,200,255));
          g.fillRect(0,0,WIDTH,HEIGHT);
          g.setColor(Color.ORANGE);
          g.fillRect(0, HEIGHT-100, WIDTH,100);
          g.setColor(Color.GREEN);
          g.fillRect(0,HEIGHT-110,WIDTH,10);
          g.setColor(Color.red);
          g.fillRect(x, y, 15, 15);
          g.setFont(new Font("Arial",15,15));
  
          int colorman=0;
          g.setColor(new Color(200,200,40));
  
          for(Rectangle rect:walls){
              paintWall(rect,g);
          }
      }
  
      @Override
      public void actionPerformed(ActionEvent e) {
          while(run==true){
              repaint();
  
              ticks ++;
              if(jump){
                  if(ticks%8==0){
                      gravity=-10;
                  }
              } 
              else if(ticks%8==0 &amp;&amp; gravity&lt;15 &amp;&amp; jump==false){
                  gravity+=2;
  
              }
              y += gravity; 
  
              for(Rectangle rect:walls){
                  rect.x -=10;
  
              }
              for(int i=0;i&lt;walls.size();i++){
                  Rectangle r=walls.get(i);
  
                  if(r.x+r.width&lt;0){
                      walls.remove(r);
  
  
                      addWall(false);     
  
                  }
              }
  
          }
      }
  }
  </code></pre>