Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. public static class Counter
  2. {
  3. boolean stopTimer = false ;
  4.  
  5. Timer timer; // creating new timer
  6.  
  7. // constructor intitializes amount of seconds
  8. public void Counter()
  9. {
  10. timer = new Timer();
  11. timer.schedule(new countdown(), 5*1000);
  12. int choice = keyboard.nextInt();
  13. if(choice == 1)
  14. {
  15. timer.cancel();
  16. playGame();
  17. }
  18.  
  19. }
  20.  
  21. class countdown extends TimerTask
  22. {
  23. @Override
  24. public void run()
  25. {
  26. if(!stopTimer)
  27. {
  28. System.out.format("Returning to main menu%n");
  29.  
  30. stopTimer = true;
  31.  
  32. }
  33.  
  34. }
  35.  
  36. }
  37.  
  38.  
  39.  
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement