You create and start a javax.swing.Timer to run every "n" millisecs.
It has a reference to some class with an ActionPerformed method, and it calls that method every "n" miliisecs.
eg:
import javax.swing.Timer;
...
// in main program initialisation...
int milliSecsBetweenRuns = 100;
Timer timer = new Timer(milliSecsBetweenRuns , new ThingToRunRepeatedly());
...
// in rsponse to space key pressed...
timer.start();
...
// in response to space key released...
timer.stop();
... and the thing that gets called is as simple as this...
// gets called buy the timer every 100 mSec as long as space key is down...
class ThingToRunRepeatedly implements ActionListener {
public void actionPerformed(ActionEvent e) {
// update x,y coords etc
// call repaint for the main window
}
}