0

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();
            }
         }
      }
   }
3
Contributors
2
Replies
12
Views
2 Years
Discussion Span
Last Post by JamesCherrill
0

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?

0

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)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.