Fichier #orrpdo31-2877 - JAVA - Code source

Téléchargé par un utilisateur anonyme - 09/03/2010 21:29 - 71 affichages
Code source
  1. class Threads
  2. {
  3. 	public static void main(String args[])
  4. 	{
  5. 	new Thread1().start();
  6. 	}
  7. }
  8.  
  9. class Thread1 extends Thread
  10. {
  11. 	public void run()
  12. 	{
  13. 		int counter = 1;
  14. 		while (counter < 4)
  15. 		{
  16. 			try
  17. 			{
  18. 				sleep(1000); //pause the thread for 1 second
  19. 				System.out.println(counter); //print the number of seconds
  20. 			}
  21. 			catch (InterruptedException e){ } //exception must be caught to allow the sleep method to work
  22. 			counter++;
  23. 		}
  24. 		stop(); //stops the current thread
  25. 	}
  26. }