title: How to make a loop or something that does a task every 5 seconds and then reset itself?
body: <p>I need to have the for loop at the bottom do everything in the body every 5 seconds but it's not working for some reason! Sorry if this sounds very dumb, I am very new to java! If you could help, that'd be great! Thanks! :)</p>
  
  <pre><code>package rBP;
  
  import java.applet.Applet;
  import java.awt.Color;
  import java.awt.Font;
  import java.awt.Graphics;
  import java.awt.event.MouseEvent;
  import java.awt.event.MouseListener;
  
  public class Main extends Applet implements MouseListener {
  public void init() {
      super.init();
      addMouseListener(this);
  }
  
  public long numClicks = 0; // 16385
  public int autoFingerNum = 0;
  public int faultyButtonNum = 0;
  public int slickButtonNum = 0;
  public int coolButtonNum = 0;
  public int heatSinkNum = 0;
  public int superButtonNum = 0;
  public int aFCost = 30;
  public int aFValue = 1;
  public int fBCost = 75;
  public int fBValue = 3;
  public int slBCost = 300;
  public int slBValue = 10;
  public int cBCost = 1000;
  public int cBValue = 25;
  public int hSCost = 5000;
  public int hSValue = 80;
  public int suBCost = 10000;
  public int suBValue = 200;
  
  @Override
  public void paint(Graphics g) {
      this.setSize(1010, 360);
      g.setColor(Color.cyan);
      g.fillRect(0, 0, 1010, 360); // background
      g.setColor(Color.black);
      g.fillOval(47, 47, 205, 205); // button outline
      g.setColor(Color.red);
      g.fillOval(50, 50, 200, 200); // button
      g.setColor(Color.yellow);
      g.fillRect(2, 5, 290, 30); // yellow boxes
      g.fillRect(300, 25, 100, 250);
      g.fillRect(410, 25, 100, 250);
      g.fillRect(520, 25, 100, 250);
      g.fillRect(630, 25, 100, 250);
      g.fillRect(740, 25, 100, 250);
      g.fillRect(850, 25, 100, 250);
      g.setColor(Color.black);
      g.drawLine(300, 100, 400, 100); // lines on yellow boxes
      g.drawLine(410, 100, 510, 100);
      g.drawLine(520, 100, 620, 100);
      g.drawLine(630, 100, 730, 100);
      g.drawLine(740, 100, 840, 100);
      g.drawLine(850, 100, 950, 100);
      g.drawLine(300, 190, 400, 190);
      g.drawLine(410, 190, 510, 190);
      g.drawLine(520, 190, 620, 190);
      g.drawLine(630, 190, 730, 190);
      g.drawLine(740, 190, 840, 190);
      g.drawLine(850, 190, 950, 190);
      g.fillRect(307, 197, 86, 71); // boxes around "buy" buttons
      g.fillRect(417, 197, 86, 71);
      g.fillRect(527, 197, 86, 71);
      g.fillRect(637, 197, 86, 71);
      g.fillRect(747, 197, 86, 71);
      g.fillRect(857, 197, 86, 71);
      g.setColor(Color.red);
      g.fillRect(310, 200, 80, 65); // red "buy" buttons
      g.fillRect(420, 200, 80, 65);
      g.fillRect(530, 200, 80, 65);
      g.fillRect(640, 200, 80, 65);
      g.fillRect(750, 200, 80, 65);
      g.fillRect(860, 200, 80, 65);
      g.setColor(Color.black);
      g.setFont(new Font("default", Font.BOLD, 12));
      g.drawString("Number of Points: " + numClicks, 5, 25); // num of points
      g.setFont(new Font("default", Font.BOLD, 20));
      g.drawString("DO", 135, 120);
      g.drawString("NOT", 127, 150);
      g.drawString("PRESS", 115, 180);
      g.setFont(new Font("default", Font.BOLD, 16));
      g.drawString("AutoFinger", 310, 50);
      g.drawString("FaultyButton", 411, 50);
      g.drawString("SlickButton", 524, 50);
      g.drawString("CoolButton", 635, 50);
      g.drawString("HeatSink", 754, 50);
      g.drawString("SuperButton", 851, 50);
      g.drawString("+1p/5s", 310, 75);
      g.drawString("+3p/5s", 434, 75);
      g.drawString("+10p/5s", 540, 75);
      g.drawString("+40p/5s", 648, 75);
      g.drawString("+100p/5s", 756, 75);
      g.drawString("+500p/5s", 866, 75);
      g.drawString("Buy: 30P", 315, 240);
      g.drawString("Buy: 75P", 425, 240);
      g.drawString("Buy: 300P", 530, 240);
      g.setFont(new Font("default", Font.BOLD, 15));
      g.drawString("Buy: 1000P", 642, 240);
      g.drawString("Buy: 5000P", 752, 240);
      g.setFont(new Font("default", Font.BOLD, 13));
      g.drawString("Buy: 10000P", 862, 240);
      g.setFont(new Font("default", Font.BOLD, 12));
      g.drawString("aFNumber: " + autoFingerNum, 305, 150);
      g.drawString("fBNumber: " + faultyButtonNum, 415, 150);
      g.drawString("sBNumber: " + slickButtonNum, 525, 150);
      g.drawString("cBNumber: " + coolButtonNum, 635, 150);
      g.drawString("hSNumber: " + heatSinkNum, 745, 150);
      g.drawString("sBNumber: " + superButtonNum, 855, 150);
  
  }
  
  @Override
  public void mouseClicked(MouseEvent e) {
  
      if ((e.getX() &gt; 50 &amp;&amp; e.getX() &lt; 250)
              &amp;&amp; (e.getY() &gt; 50 &amp;&amp; e.getY() &lt; 250)) {
          numClicks++;
          repaint();
      }
      if ((e.getX() &gt; 310 &amp;&amp; e.getX() &lt; 390)
              &amp;&amp; (e.getY() &gt; 200 &amp;&amp; e.getY() &lt; 265)
              &amp;&amp; numClicks &gt; (aFCost - 1)) {
          autoFingerNum++;
          numClicks -= aFCost;
          repaint();
      }
      if ((e.getX() &gt; 420 &amp;&amp; e.getX() &lt; 500)
              &amp;&amp; (e.getY() &gt; 200 &amp;&amp; e.getY() &lt; 265)
              &amp;&amp; numClicks &gt; (fBCost - 1)) {
          faultyButtonNum++;
          numClicks -= fBCost;
          repaint();
      }
      if ((e.getX() &gt; 530 &amp;&amp; e.getX() &lt; 610)
              &amp;&amp; (e.getY() &gt; 200 &amp;&amp; e.getY() &lt; 265)
              &amp;&amp; numClicks &gt; (slBCost - 1)) {
          slickButtonNum++;
          numClicks -= slBCost;
          repaint();
      }
      if ((e.getX() &gt; 640 &amp;&amp; e.getX() &lt; 720)
              &amp;&amp; (e.getY() &gt; 200 &amp;&amp; e.getY() &lt; 265)
              &amp;&amp; numClicks &gt; (cBCost - 1)) {
          coolButtonNum++;
          numClicks -= cBCost;
          repaint();
      }
      if ((e.getX() &gt; 750 &amp;&amp; e.getX() &lt; 830)
              &amp;&amp; (e.getY() &gt; 200 &amp;&amp; e.getY() &lt; 265)
              &amp;&amp; numClicks &gt; (hSCost - 1)) {
          heatSinkNum++;
          numClicks -= hSCost;
          repaint();
      }
      if ((e.getX() &gt; 860 &amp;&amp; e.getX() &lt; 940)
              &amp;&amp; (e.getY() &gt; 200 &amp;&amp; e.getY() &lt; 265)
              &amp;&amp; numClicks &gt; (suBCost - 1)) {
          superButtonNum++;
          numClicks -= suBCost;
          repaint();
      }
  
  }
  
  @Override
  public void mouseEntered(MouseEvent arg0) {
  }
  
  @Override
  public void mouseExited(MouseEvent arg0) {
  }
  
  @Override
  public void mousePressed(MouseEvent arg0) {
  }
  
  @Override
  public void mouseReleased(MouseEvent arg0) {
  }
  
  public void output() {
      for (int i = 0; i &gt;= 50; i++) {     //&lt;- I just set it at 50 for testing              purposes
                      i = 0;
          numClicks += autoFingerNum * aFValue;
          numClicks += faultyButtonNum * fBValue;
          numClicks += slickButtonNum * slBValue;
          numClicks += coolButtonNum * cBValue;
          numClicks += heatSinkNum * hSValue;
          numClicks += superButtonNum * suBValue;
      }
  }
  </code></pre>
  
  <p>}</p>