title: Java 2D game: repaint
body: <p>I am creating a very simple game for my homework and right now I am solving the following problem: </p>
  
  <p>in this game when you <code>click</code> on the <code>shape</code> (for now it is just a circle) it should dissapear and render a new one somewhere else (you are collecting points when you hit that shapes, that´s the point) and my problem is in the <code>mouseClicked</code> method, i think. I put some control <code>System.out.println()</code> there and everytime when the program reach this method it displays as many prints as there was circles. I mean, if you click on the first circle it displays one print, if you click on the second circle it diplays two prints and so on. Can you help me pls? I just started with the <code>swing</code> and <code>awt</code> and I don´t have much time for thorough study. Thank you so much.</p>
  
  <pre><code>public class Shape extends JPanel implements ActionListener{
  
      Graphics2D g2;
      Ellipse2D circle;
      Timer t = new Timer(2000, this);
      int x, y, count;
      JLabel counting;
  
      public Shape(JLabel counting){
          this.counting = counting;
      }
  
  
      public void paintComponent(Graphics g){
  
          super.paintComponent(g);
  
          g2 = (Graphics2D)g;
  
          ListenForMouse lForMouse = new ListenForMouse();
  
          addMouseListener(lForMouse);
  
          Random ran = new Random();
  
          int green = ran.nextInt(256);
          int red = ran.nextInt(256);
          int blue = ran.nextInt(256);
  
          Color randomColor = new Color(green, red, blue);
  
          int wid = ran.nextInt(101) + 50;
  
          x = ran.nextInt(650);
          if(x &gt; wid)
              x = x - wid;
          y = ran.nextInt(600);
          if(y &gt; wid)
              y = y - wid;
  
          circle =  new Ellipse2D.Double(x,y,wid,wid);
  
          t.start();
  
          g2.setColor(randomColor);
  
          g2.fill(circle);
  
      }
  
      @Override
      public void actionPerformed(ActionEvent arg0) {
          repaint();
  
      }
  
  
      private class ListenForMouse implements MouseListener{
  
          @Override
          public void mouseClicked(MouseEvent e) {
  
  
                  System.out.println("Control before");
  
              if(circle.contains(e.getPoint())){
  
                  count++;    
  
                  counting.setText(Integer.toString(count));
  
                  t.stop();
  
                  repaint();
  
                  System.out.println("Control in");
              }
              System.out.println("Control out");
  
          }
      }
  }
  </code></pre>