Having program wait for a period of time

I have a program that I am creating that will need to paint something to the panel every few seconds. I have some code like so:
public void paintBar(Graphics g, Graphics2D g2)
          for(int i = 0; i < 325; i++)
               //draw a rectangle
               double leftX = 36;
               double topY = 76;
               double width = i;
               double height = 48;
               double test = 100;
               Rectangle2D rect = new Rectangle2D.Double(leftX, topY, width, height);
               g2.setPaint(Color.yellow);
               g2.fill(rect); //fill rectangle with color
               g2.setPaint(new Color(204, 204, 153)); //change paint to background color for erase
               eraseMessage(g);
               calculatePercentage(i);
               g2.setPaint(Color.black); //change paint color back to black for message
               printMessage(g);
//NEED TO WAIT HERE FOR A PERIOD OF TIME
//THEN CONTINUE WITH LOOP.
The problem that I am having is that I tried to use different wait() meathods and it seems to get to the wait meathod and just freeze. The painting is never done until the wait command is complete and then the all of the painting is totally finished. I never see it progressing.
Any ideas?
Thanks

You could use a scheduled event...
public void run() {
     Timer timer = new Timer(false);          // Create Timer
     class Refresh extends java.util.TimerTask {     
          // Create repaint event
          public void run(){repaint();}
     timer.schedule(new Refresh(),0,10);     // Schedule repaint
}Call this when you run your program, and place all your paint and update methods into a paint(graphics g) method.
Then, the timer will continuously run repaint repeatedly.
You can then insert a single event timer (i don't know how off hand, but they are in the API under Timer events), that kills the origional event timer after X ammount of time.

Similar Messages

  • Can I make a function wait for a period of time?

    Hey everyone
    I just wanted some idea's on how best to tackle this problem
    in actionscript.
    All I want is that when a button is pressed it fades out the
    current page and then fades in the new page to be displayed. How
    ever when trying to fade out the current page i doesn't because it
    goes to the label and starts to play but the next part of the
    script tells it to go straight to the label to load the new page.
    Does anyone have a clever way of making it wait till the current
    page is faded out?
    If worse comes to worse can I just make it wait a set period
    of time before fading in the new page?
    Ive attached a bit of the current code and comment it with
    where the current page is faded out.
    Thanks in advance for any help
    Gaunt

    What I'm struggling to get my head round though is how to I
    get it to know when the fade out code is finished?
    Because the way I have programmed it at the moment,
    everything is done from one action script that registers the last
    viewed page and then when the new page is clicked it will just call
    gotoAndPlay to the point where my pages_mc will play fading out the
    current page, then after that it will call gotoAndPlay on the
    pages_mc to play the fade in of the new page.
    I just dont see how I call the second gotoAndPlay function
    once I know the first gotoAndPlay function has ended.
    Does that make any sense or am I just being stupid??
    Thanks for the help again though kglad

  • Serious issue wherein every program lags for excessive periods of time

    so i have a bit of a serious problem but am very confused about it. last night i put my computer to sleep (possibly during an electrical storm, i'll admit) and when i went to wake it up this morning, i realized it was turned off. so i turned it on, and it started up and then told me that my date was set before 2001 and so on and so forth (it had reset the time, i'm not really that concerned about this, i've seen it happen before.) so the time is set to somewhere in 1969. but that isn't the problem. when i went to try to change the date and time with system preferences, it showed me the spinning wheel but never loaded. so i tried opening other programs. every single program does this. it starts opening it but lags tremendously and never actually finishes the task. i tried to open mac help and it finally opened the window for it but didn't load any information. i really have no idea what could have caused this and am more than a little concerned, as i'm unable to use my own computer at this point. any ideas before i call someone in?
    powermac g4   Mac OS X (10.4.6)   1024mb ram

    unfortunately i cannot open any windows, no. the color wheel spins for an indefinite period of time. any program i try to open essentially freezes. i also cannot successfully restart the computer via the apple menu, the only ways i can restart are if i use the power button directly or if i restart from the login screen. i can't open anything, really. it tries to open the programs and starts to but after a while seems to time out. it indicates that it's still trying but after a few minutes shows no progress. if my screensaver goes on and i wake my computer up again, it freezes on the screensaver and can't get out of it. i tried starting up from the tiger disk but that wasn't working either (when i start up from any disk that isn't my hard drive, my monitor resolution isn't recognized, so it won't display anything - so every time i've had to upgrade in the past i've borrowed another monitor for the process).

  • I want to use my iphone for wi-fi connection, without calls or texts or having a carrier for a period of time. How should I do it??

    I want to use my iphone to connect to wi-fi without calls or texts and without a carrier. How should I do that??

    Turn on airplane mode, turn wifi back on.

  • Possible loop deadline monitoring for a period of time?

    Hi All,
    Here is our scenario.. We have a task sent to the managers inbox with deadline monitoring on it.  If the manager does not action this task, we set this task to obsolete and then we want to send a reminder email every day until the manager performs the required action.
    So the problem.. originally this email was to be a task but the loop would not work with the task as it's waiting on action from the user.  We changed this task to an email and it looped as expected however the only way I could think to put a wait for a period of time before another email is sent is by actually counting down the time in a method.
    However, the problem with this is that wf-batch is locking the worklfow so it can never complete, even if the event to complete the workflow is triggered.  wf-batch has it locked so the workflow can never complete, so it loops infinitely.
    So my question.. is it possible to repeatedly send notifications to a manager at specifically defined time intervals without locking the workflow?
    Below is how the workflow currently looks:
    Any guidance on this would be most gratefully received!
    Thanks in advance,
    Liz.

    Hi Liz
    in your wait step, do not count down the time.
    Instead keep the method as a dummy method with no code.
    In the wait step, use the deadline monitoring - Requested Start - set it to current date + 1 day
    The step will start 1 day after 'today' , execute nothing in Dummy method and then go on to the mail step
    I am sure that the deadline monitoring job is running because "Latest End" of the first task is executed in your system. So the same job will take care of Requested Start of the wait step.
    regards,
    Modak

  • How to block internet connection for a period of time?

    Hey guys is there a way to block internet connection via a lan connection for a period of time? A program that when my pc is boot up it run secretly and at the time schedule it block the internet connection with no pop up. When i not at home some person
    used my pc to use my internet connection everyday. I can't lock up my pc since my brother or my dad used it.
     

    Hi,
    You could create a schedule task to achieve this.
    The detailed solution please refer to this thread:
    https://social.technet.microsoft.com/Forums/en-US/7544cbed-507d-4eef-907d-bafb99b45411/disable-internet-for-a-set-period-of-time?forum=w7itprogeneral
    Karen Hu
    TechNet Community Support

  • 4 albums purchased from iTunes yesterday have songs not playing all the way through. They play for a period of time and skip to the next song. Everytime they are played. Can anyone help?

    Some songs I purchased last night are not playing all the way through. Several songs from the 4 albums I purchased play for a period of time then just skip to the next song. The songs that do this, do it everytime they are played at the exact same spot. The songs that are affected skip to the next on iTunes on my PC which is updated to the most current iTunes and my 160gb iPod classic. Everytime they are played at the exact same spot. However on my other device, iPhone 4s all songs play just fine. I have almost 7,000 songs on my iPod and this has never happened before and I have played it awhile since downloading those albums yesterday. This is only happening with the albums purchased yesterday. Can anyone help me figure out what is wrong?

    I'm having the same issue with a few songs I just downloaded. It skips randomly in the middle of the song.

  • Im on wifi but sometimes when i try and send imessages it wont let me for a period of time why?

    Im on wifi but sometimes when i try and send imessages it wont let me for a period of time why?

    If not thsi:
    iOS: Wi-Fi or Bluetooth settings grayed out or dim
    One user reported that placing the iPod in the freezer fixed the problem. A trick that works frequently with iPhones:
    Settings > AirPlane Mode ON, Do Not Disturb ON
    Power down and wait 5-10 minutes
    Power up
    Settings > AirPlane Mode OFF, Do Not Disturb OFF
    If not successful, an appointment at the Genius Bar of an Apple store is usually in order.
    Apple Retail Store - Genius Bar
    Then
    Does the iOS device connect to other networks? If yes that tend to indicate a problem with your network.
    Does the iOS device see the network?
    Any error messages?
    Do other devices now connect?
    Did the iOS device connect before?
    Try the following to rule out a software problem:                
    - Reset the iOS device. Nothing will be lost
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Power off and then back on your router
    .- Reset network settings: Settings>General>Reset>Reset Network Settings
    - iOS: Troubleshooting Wi-Fi networks and connections
    - Wi-Fi: Unable to connect to an 802.11n Wi-Fi network      
    - iOS: Recommended settings for Wi-Fi routers and access points
    - Restore from backup. See:
    iOS: How to back up
    - Restore to factory settings/new iOS device.
    If still problem and it does not connect to any networks make an appointment at the Genius Bar of an Apple store since it appears you have a hardware problem.
    Apple Retail Store - Genius Bar

  • After using my browser (any of them) for a period of time I get a message saying that a page can't be opened. I have to reboot again. Clearing the cache doesn't help.

    After using my browser (any of them) for a period of time I get a message saying that a page can't be opened. I have to reboot again. Clearing the cache doesn't help. It's very annoying. It even happened in the middle of a chat with Apple online support. I'd be very grateful for help!

    Several things come to mind ... when you say your wife uses the same system with a different login and doesn't have issues, that suggests looking at your login items. Go to System Preferences (on your dock or on your hard drive in Applications), accounts, and on your account look at login items. Anything there that shouldn't be or isn't used? If you don't know, create a new account for yourself with no login items, and see if you still have the issue.
    Next, I would run OnyX, which is a free disk maintenance program. You can download it from http://www.titanium.free.fr/download.php . Do the tasks on the cleaning and maintenance tabs. Before using any disk maintenance software, you should have a system backup. I periodically run it, and others have found that it can help with performance.
    You might look at how you're system is using memory. You should have enough but it's easy to check. Bring up the Activity Monitor (on your hard drive in Applications/Utilities), and look at the system memory tab. Note page ins and page outs. If page outs are 10% to 15% more than page ins, you can use more memory for the programs you run. A page out occurs when memory is full and OS X has to write a section of memory to the hard drive. Too much of this can really impact performance. The optimal situation is for page outs to be zero.  Note these  values reset on a system boot.

  • Program crashing after extended periods of time

    I have a program that takes measurements at approximately every 100 milliseconds. After about 4 hours though the program always crashes. I'm thinking this may have been due to the file size - every 100 ms two numbers are recorded to a .txt file. I'm beginning to think this is not the case because I've run another program that has been able to run for longer periods of time and develop larger file sizes. Does anyone have any idea why it may be crashing consistently and if there is any way around it? Thanks!

    Post some code. Otherwise it could be almost anything.
    Les Hammer

  • To display splash screen for certian period of time using threads

    i want to write a program to display splash screen for certian period of time using threads. could some one help me

    If you just want a splash screen: [http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/splashscreen/|http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/splashscreen/]
    If you want to learn threads: [http://java.sun.com/docs/books/tutorial/essential/concurrency/|http://java.sun.com/docs/books/tutorial/essential/concurrency/]

  • Screen freezes randomly for short periods of time [Solved]

    I'm not sure when this started to happen, but my screen will freeze (not refresh) randomly for short periods of time (about 5 seconds). The mouse cursor still active and anything I click on will eventually catch up once the screen refreshes.
    I'm assuming this is an Xorg issue, or perhaps and Nvidia issue, but here are some details:
    KDE 4.4
    Kernel 2.6.32-ARCH 64
    Nvidia 195.36.15
    And here is my Xorg.conf:
    # nvidia-xconfig: X configuration file generated by nvidia-xconfig
    # nvidia-xconfig: version 1.0 (buildmeister@builder58) Tue Oct 20 21:25:04 PDT 2009
    Section "ServerLayout"
    Identifier "Layout0"
    Screen 0 "Screen0" 0 0
    InputDevice "Keyboard0" "CoreKeyboard"
    InputDevice "Mouse0" "CorePointer"
    InputDevice "SynapticsTouchpad" "SendCoreEvents"
    EndSection
    Section "Files"
    EndSection
    Section "Module"
    Load "glx"
    Load "synaptics"
    EndSection
    Section "InputDevice"
    # generated from default
    Identifier "Mouse0"
    Driver "mouse"
    Option "Protocol" "auto"
    Option "Device" "/dev/psaux"
    Option "Emulate3Buttons" "no"
    Option "ZAxisMapping" "4 5"
    EndSection
    Section "InputDevice"
    # generated from default
    Identifier "Keyboard0"
    Driver "kbd"
    EndSection
    Section "InputDevice"
    Identifier "SynapticsTouchpad"
    Driver "synaptics"
    Option "AlwaysCore" "true"
    Option "/dev/input/mice"
    Option "/dev/psaux"
    Option "VerticalEdgeScroll" "True"
    Option "HorizontalEdgeScroll" "True"
    Option "CornerCoasting" "true"
    Option "TapButton1" "1"
    Option "TapButton2" "2"
    EndSection
    Section "Monitor"
    Identifier "Monitor0"
    VendorName "Unknown"
    ModelName "Unknown"
    HorizSync 28.0 - 33.0
    VertRefresh 43.0 - 72.0
    Option "DPMS"
    EndSection
    Section "Device"
    Identifier "Device0"
    Driver "nvidia"
    VendorName "NVIDIA Corporation"
    EndSection
    Section "Screen"
    Identifier "Screen0"
    Device "Device0"
    Monitor "Monitor0"
    DefaultDepth 24
    Option "NoLogo" "True"
    Option "RenderAccel" "True"
    Option "TripleBuffer" "True"
    Option "BackingStore" "True"
    SubSection "Display"
    Depth 24
    EndSubSection
    EndSection
    Needless to say this is very annoying/embarrassing when I try and show people stuff, so any help would be greatly appreciated!
    Last edited by fini_fly (2010-05-21 13:47:20)

    What you can try is to add:
    option "UseEvents" "false"
    (also try "true" and see if it works for you)
    to your xorg.conf under the device section. Play with both false and true settings, UseEvents is somewhat related to the short freezes and the nvidia guys mentioned they disabled this feature a few driver releases ago (as far as i know from researching their forums). Otherwise we probably have to wait for a new driver series.
    Another tweak would be to check if you use MSI for your nvidia card:
    cat /proc/interrupts:
    22: 0 4 1106 297835 IO-APIC-fasteoi ohci_hcd:usb3
    23: 1 17 3275 890447 IO-APIC-fasteoi hda_intel
    27: 2 13 1035 342106 PCI-MSI-edge ahci
    28: 5 337 26356 7568321 PCI-MSI-edge eth0
    29: 6 92 10219 1998835 PCI-MSI-edge nvidia
    NMI: 0 0 0 0 Non-maskable interrupts
    add this to /etc/modprobe.d/options.conf: (does not work with all nvidia cards but i can confirm it works with the 200 series)
    options nvidia NVreg_EnableMSI=1
    While using MSI slightly improves performance some people reported it also shortens the occasional freezes.
    As said in the post above this is only for nvidia and it may or may not help for some gpu's.
    Best regards

  • For OS X: Whenever I have internet access my disk is running continuously for a period of time without any activity on my part.  When I close internet access the disk activity stops.  Who is fishing for data?

    For OS X v5 or 6: Whenever I have internet access my disk is running continuously for a period of time without any activity on my part.  When I close internet access the disk activity stops.  Who is fishing for data?

    Thanks for your reply.  I don't use itunes so that couldn't be it.  Reading about Little Snitch and Hands Off, however,  educated me about the data harvesting in many apps and that when buying from the AppStore one will more likely get Apps with benign data harvesting.

  • Ignore user imput for a period of time

    Hi there
    Was wondering whether anybody could answer this question;
    Is there a way to tell Director to ignore all mouse clicks
    for a period of time?
    I am swinging a qtvr sprite with various commands attached to
    the swing action, including a timer.
    In order for this to work out the user should not be able to
    interfer with the swing action once it is in motion. They should
    only regain control once the swing is complete and the commands
    have been carried out.
    Is this possible??
    Thankee kindly...

    I think the simple but dirty trick, placing a transparant on
    top of your
    sprite/stage (rectangle form the tools menu, with no border),
    will work.
    Attach behaviour with empty mouseUp and mouseDown to the
    transparant, so
    mouseactions do not pass, like:
    on mouseUp me
    end
    on mouseDown me
    end
    Move the transparant in/out when needed

  • My wifi button is frezon and I tried turning my phone off for a period of time and reset my phone but the button is still frezon it want slide over to turn on my wifi. Is there any other way to fix without going to apple to get it fixed?

    My wifi button is frezon and I tried turning my phone off for a period of time and reset my phone but the button is still frezon it want slide over to turn on my wifi. Is there any other way to fix without going to apple to get it fixed?

    Hey Posada143, You can still try the rice thing, but do not expect much, as roaminggnome has stated. The rice only works if you do it ASAP and leave the iPod off-- do not attempt use, turn on or charge until it is completely dried out. This is probably academic at this point but remember this for the next time: The drying can take 10 days. You put the uncooked rice and iPod in a sealed bag, change the rice every couple of days. This creates a low humidity environment and draws the moisture out of the iPod, but it takes time. Turn your iPod on to earlier, and you run the risk of shorting out, damaging the components inside. Even if done correctly it can spotty. If you do get the iPod to work (and this may require Resetting, Restoring or attempting to place it in DFU recover mode) the first thing you do is make backups, because you never know how long it will continue to work. As for your pictures, if you can't get your iPod to work, you can try data retrieval companies, however; there is no guaranty it will work and it tends to be very expensive. In the future get in the habit of as making backups, because you just don't know. And invest in and use a water tight case. Hope this helps, Good luck. Cheers.

Maybe you are looking for