public void run() 
	{
		long beforeTime, timeDiff, sleep;
      
		while (true) 
		{
			beforeTime = System.currentTimeMillis();

			action();
			repaint();

			timeDiff = System.currentTimeMillis() - beforeTime;
			sleep = gamespeed - timeDiff;

			if (sleep < 0)
				sleep = 0;
			try 
			{
				Thread.sleep(sleep);
			} 
			catch (InterruptedException e) 
			{
				System.out.println("interrupted");
			}
			while(keylist.size() > 0)
			{
				int key = keylist.remove();
				if (!gameover) 
					for (int x = 0; x < players.size(); x++)
						players.get(x).keyPressed(key);
			}
		}
	}