I am wanting to call a method every 10 seconds, how do I go about this?
I have tried to create a separate class with this code:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import javax.swing.Timer;
import java.awt.event.*;
import java.util.*;
public class TimerDemo implements ActionListener {
Timer t = new Timer(10000,this);
TimerDemo() {
t.start();
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == t)
{
System.out.println ("Testing");
}
}
}
This works, but I am not sure how to reference the world to call a public method.
How can I do this please? Or is there a better way to call a method every 10 seconds?
thanks