Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 08-18-2010, 10:10 AM   #11
In Runtime
 
hockeygoalie5's Avatar
 
Join Date: Dec 2009
Location: United States
Posts: 297
Default Re: 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.'.
__________________

hockeygoalie5 is offline   Reply With Quote
Old 08-18-2010, 10:43 AM   #12
Site Team
 
berry120's Avatar
 
Join Date: Jul 2009
Location: England, UK
Posts: 3,425
Default Re: Java Problems

Quote:
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...
__________________

__________________
Save the whales, feed the hungry, free the mallocs.
berry120 is offline   Reply With Quote
Old 08-18-2010, 10:52 AM   #13
In Runtime
 
hockeygoalie5's Avatar
 
Join Date: Dec 2009
Location: United States
Posts: 297
Default Re: Java Problems

Works now, thanks for the help! I've discovered the timer.cancel() method.
__________________

hockeygoalie5 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 03:21 AM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0