How do you setDelay


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 11 of 11

Thread: How do you setDelay

  1. #1
    Join Date
    May 2004
    Posts
    7

    How do you setDelay

    hi
    im making a tic-tac-toe game and i want to set a delay of one second between moves from user and computer

    i dont know how to use
    setDelay(int)

    can you give me an example

    thanks chris

  2. #2
    Join Date
    May 2004
    Posts
    26
    Thread.sleep() ??????????

  3. #3
    Join Date
    May 2004
    Posts
    7

    Timer didnt work

    i tried
    Thread.sleep(1000);

    and give me error must be caught

  4. #4
    Join Date
    May 2004
    Posts
    7

    How come??

    Timer timer = new Timer();

    this doesnt work give me an error

    C:\Documents and Settings\chris\Desktop\GAMES BY CHRIS\TicTacToe.java:12: cannot resolve symbol
    symbol : constructor Timer ()
    location: class javax.swing.Timer
    Timer timer = new Timer();
    ^
    1 error

    please help!!

  5. #5
    Join Date
    Feb 2004
    Posts
    541
    there is no constructor in javax.swing.Timer that has no parameters, so essentially you're trying to use a method that doesn't exist. Obviously the compiler won't let you do that go here to see the api for javax.swing.Timer and it will show you how to use it and what it does.

  6. #6
    Join Date
    May 2004
    Posts
    7

    ???

    Thanks for the link

    im still haveing trouble using it though

    i tried

    setDelay(100);

    gives me this error


    C:\Documents and Settings\chris\Desktop\GAMES BY C HRIS\TicTacToe.java:88: cannot resolve symbol
    symbol : method setDelay (int)
    location: class TicTacToe
    setDelay(10000);
    ^
    1 error

    Tool completed with exit code 1


    is that thr right way to format it?
    Am i missing something??

  7. #7
    Join Date
    May 2004
    Posts
    7
    Baically what i wanted to use the timer for is for stoping the program for one second

  8. #8
    Join Date
    Feb 2004
    Posts
    541
    the error means that the compiler doesn't recognise the method setDelay(). You need to specify the object that the method belongs to since I assume it's not a method in your class right? Something like someObject.setDelay().

    I'm not sure if you understood my last post so i'll clarify it now. You tried to make a Timer object using a constructor with no paramters. The class Timer doesn't have such a constructor, it only has construcors that have parameters in them. The link i gave in the last post goes to the API for Timer and shows how to use it.

  9. #9
    Join Date
    May 2004
    Posts
    11
    ummm....

    why not try putting a try/catch around the sleep call.

    try
    {
    Tread.sleet(1000);
    }
    catch(InterruptedException e){}

    That should be all you need to do.

    Dave

  10. #10
    Join Date
    May 2004
    Posts
    26
    Originally posted by sirHensley
    try
    {
    Tread.sleet(1000);
    }
    Tread.sleet?

  11. #11
    Join Date
    May 2004
    Posts
    11
    DOH!!!

    We definitely dont need any sleet in our java code. How about using sleep instead...and we probably want to use a Thread and not a Tread .
    try
    {
    Thread.sleep(1000);
    }
    catch(InterruptedException e){}


    I think I need typing lessons.

    Dave

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center