Results 1 to 4 of 4
  1. #1
    gregsakas is offline Member
    Join Date
    Aug 2012
    Posts
    11
    Rep Power
    0

    Default How can I have two different types of timers in one program?

    Is it even possible? I tried declaring
    Java Code:
    javax.swing.Timer newt=new Timer(1000, new ActionListener(){...});
    and
    Java Code:
    java.util.Timer timer=new Timer();
    but it gives me the error: Type mismatch: cannot convert from javax.swing.Timer to java.util.Timer for the second. I have both types imported and I they are in different methods of the program.

    EDIT: I realized that I only had the javax.swing.Timer; imported specifically. If it is not possible, then how can I use .scheduleAtFixedRate with a swing timer?
    Last edited by gregsakas; 08-01-2012 at 10:17 PM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: How can I have two different types of timers in one program?

    Rather than ask us to answer a specific code question, you may be better off first telling us what overall problem you're trying to solve and some background into your problem (for example, is this in fact for a Swing GUI?) as the best solution may vary depending on this.

  3. #3
    gregsakas is offline Member
    Join Date
    Aug 2012
    Posts
    11
    Rep Power
    0

    Default Re: How can I have two different types of timers in one program?

    I need one timer that can do:
    Java Code:
    timer.scheduleAtFixedRate(...);
    and one timer that can do:
    Java Code:
    Timer newtimer=new Timer(1000, new ActionListener() { });
    and as far as I know there isn't one timer that does both.

    EDIT: They need to be in the same program. That's really all I need.

  4. #4
    gregsakas is offline Member
    Join Date
    Aug 2012
    Posts
    11
    Rep Power
    0

    Default Re: How can I have two different types of timers in one program?

    I just fixed the problem:
    You need to have the type of timer after new...
    Example
    Java Code:
    javax.swing.Timer newtimer=new javax.swing.Timer(1000, new ActionListener() { });

Similar Threads

  1. I need help with timers
    By Chris Rice in forum New To Java
    Replies: 15
    Last Post: 09-04-2013, 07:02 PM
  2. Use both Timer types in the same program
    By Colonel Q in forum New To Java
    Replies: 4
    Last Post: 12-04-2011, 07:05 PM
  3. Can Timers only have one task?
    By CuddlyKittens11 in forum Advanced Java
    Replies: 1
    Last Post: 05-21-2011, 06:50 AM
  4. Help - Swing Timers, Two Keypresses
    By Gheta in forum AWT / Swing
    Replies: 2
    Last Post: 07-29-2009, 09:23 PM
  5. Question on swing timers
    By Samgetsmoney in forum New To Java
    Replies: 5
    Last Post: 02-20-2009, 07:34 AM

Tags for this Thread

Posting Permissions

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