swing - How to use the Timer class to set/reset a boolean periodically? (Java) -


I am trying to create a mole game. I have used swings to create a background and with event listeners The mole images that each time they click, the score increases, but the problem I have is that they do not want to appear or show. I thought the best way to do this would be to use the timer to set up / reset a boolean. This boolean can then be passed to the set of image (unsustainable) constructor, making random that period for which images are ideal to be visible. I have tried to start a timer and task (inhalation timer) class, call the timer. (VIS) which will have to reset the bootin and then the timer runs in the schedule (), but I am getting an empty pointer exception. Am I going wrong about this?

OK, it will flip a bit with random intervals. After making some changes in the swingworker thread you can add the code to add the code. After changing it, depending on the value of the bit.

  import java.util.Timer; Import java.util.TimerTask; Import java.util.concurrent.atomic.AtomicBoolean; Public class rankbittflip {public static zero core (string [] args throws interrupted exposure (last nuclear bullion var = new nuclear bullion (wrong); last timer timer = new timer (true); random flip (timer, vera) To display; //, print every 200ms for the value (int x = 0; x & lt; 300; x ++) {System.out.println (var.get ()); Thread.Sleep (200) ;}} Private static vacuum flaps randomly (last timer timer, final nuclear bullion and RSA) {final timer Task task = new Taimrtsk () {@ Override public Boyd run ()) {Varkset (! Varkget ()); // Call SwingWorker thread here randomly flip (timer, var); }}; Timer Scheduling (work, 500+ (tall) (1500 * math. Random ()); }}  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -