title: How to use the Timer class to set/reset a boolean periodically? (Java)
body: <p>I am trying to create a whack a mole game. I have used swing to create background and add mole images with event listeners which increment a score each time they are clicked, but I am having problems setting whether they should be visible or not. I thought the best way to do this would be to use a timer to set/reset a boolean. This boolean could then be passed to the image's setVisible() constructor. Randomizing the period for which the images are visible would be ideal. I have attempted instantiating a timer and task (inheriting timertask) class, calling timer.vis(vis) which should reset the boolean and then passing task into timer.schedule() but I'm getting a null pointer exception. Am I going about this the wrong way?</p>