Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how to delay a loop that uses a timer

807600Jun 11 2007 — edited Jun 12 2007
ok i have a bit of code i need to repeat, but theres a timer inside and what happens is it repeats 5 times immediately and then the code runs after that, what i want for it to do is run once, and after it has run and the timer has stoped i want it to repeat again, i tried nesting do loops but it didn't work too well, this is my code, i just need it to repeat 5 times,
		while (played != 5  ){			

			System.out.println(play);
			if (lives != 0) {
				played += 1;
				win = 2;
				time = 7;
				int randGame = 1 + (int)(Math.random() * 5);
				gameIndex(randGame,played);
				timer.start();
				if (win == 0) {
					lives -= 1;
				}
          	} 		
		}



	static ActionListener taskPerformer = new ActionListener() {
         public void actionPerformed(ActionEvent evt) {
      		time -= 1;     		
			if (time == 1 || win == 1 || win == 0){
				timer.stop();
				
			}
			
	     }
  	};
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 10 2007
Added on Jun 11 2007
7 comments
241 views