Java Problems

I've finished the code, removed the for int i loop and replaced it with a Timer. Now, I need to have the code constantly checking for On because On is dynamic and it's only checking once, if On is true (default false) then the code won't pick it up.
Code:
        if(On) {
            Timer timer = new Timer();
            timer.schedule(new TimerTask(), 0, 35000);
        }

For more explanation, I put a println on the start button's action listener that prints On. Click it, prints true. I also put one in the if statement that prints 'On.'. Click the button, prints true, doesn't print 'On.'.
 
Now, I need to have the code constantly checking for On
Nope - that's called polling and is also a code smell (and a big resource hog!)

Instead of having an "on" variable, you'd do better to have your actionlisteners directly turn whatever it is "on" or "off" (rather than them switching a variable which is then polled.) I'm not quite sure what the code is meant to do hence the lack of specifics...
 
Back
Top Bottom