I am trying to make a code that makes a random point cloud that changes every five seconds for a minute. I have it so that it makes the inital cloud, but I am stuck on how to make it change every five seconds.

private class newCloud implements ActionListener
   {
      public void actionPerformed(ActionEvent e)
      {
         points.clear();
         Point p;
         Random generator = new Random();
         for (int i = 0; i < 100; i++)
         {
            int x = generator.nextInt(300)+100;
            int y = generator.nextInt(200)+100;
            if(i % 1 == 0)
            {
               p = new Point(x,y);
               points.add(p);
               repaint();
            }
         }
      }
   }

Recommended Answers

All 2 Replies

for the delay you can implement a thread that sleeps each time after changing the value before re-changing it, or a Timer.

what exactly have you tried?

This is a Swing context, so never use sleep etc.
It looks like this code is the "model", so best to use a Java.util.Timer (runs in its own thread)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.