Results 1 to 8 of 8
  1. #1
    chrishans is offline Member
    Join Date
    Oct 2011
    Posts
    9
    Rep Power
    0

    Default How can I change a timer's delay?

    Hi! I have a timer with its initial delay set at 200ms. and after some event happens I want to change it. What do I have to do to do this without creating a new timer? I am using a Swing timer.
    What the timer does is repaint(), I think it should be taken into acount.

    Thanks!!
    Last edited by chrishans; 11-06-2011 at 09:32 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default Re: How can I change a timer's delay?

    Have you looked at the API doc to see if the Timer class has any methods that will do what you want?

  3. #3
    chrishans is offline Member
    Join Date
    Oct 2011
    Posts
    9
    Rep Power
    0

    Default Re: How can I change a timer's delay?

    Yes, there's a setDelay method, but wherever I put it, I doesn't work as I want.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default Re: How can I change a timer's delay?

    Do you have a small program you can post to demo your problem?
    Can you explain how you want it to work.

  5. #5
    chrishans is offline Member
    Join Date
    Oct 2011
    Posts
    9
    Rep Power
    0

    Default Re: How can I change a timer's delay?

    I am working on a Snake clone game. I have a timer which "moves" the snake every 200ms by changing the position of each square of the Snake, and then repaints. I want to change that delay, decrease it, when the score reaches, eg. 10, so that the snake moves faster.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default Re: How can I change a timer's delay?

    I doesn't work as I want.
    Can you explain what the problem is?
    Can you make a small program that shows the problem?

  7. #7
    chrishans is offline Member
    Join Date
    Oct 2011
    Posts
    9
    Rep Power
    0

    Default Re: How can I change a timer's delay?

    I'm so sorry! I don't know WTF happened, but now it works. I used the setDelay method, which I had already used but didn't work. I really don't know what I did wrong the other time.
    Thanks for your time, anyway!!

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default Re: How can I change a timer's delay?

    I guess its one of those mysteries.

Similar Threads

  1. change thread.sleep() to timer.
    By MaximumDolphin in forum Java Applets
    Replies: 16
    Last Post: 04-15-2011, 12:55 AM
  2. can i set a timer delay on mouseEntered event
    By chan in forum AWT / Swing
    Replies: 1
    Last Post: 08-30-2009, 05:55 AM
  3. Replies: 6
    Last Post: 03-17-2009, 02:23 AM
  4. Replies: 0
    Last Post: 04-04-2008, 02:46 PM
  5. Replies: 0
    Last Post: 02-05-2008, 10:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •