Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By Tolls

Thread: How can I add an actionListener to a timer?

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

    Default How can I add an actionListener to a timer?

    I need to create a timer, t, with an actionlistener that tells me when it reaches 1000 milliseconds. I tried
    Java Code:
    t.addActionListener();
    but it gave me an error.

    EDIT: I don't know if this helps but my declaration for the timer is:
    Java Code:
    Timer t=new Timer();
    Last edited by gregsakas; 08-01-2012 at 04:48 PM.

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,811
    Rep Power
    19

    Default Re: How can I add an actionListener to a timer?

    And you don't think telling us exactly what the error is might be useful?
    If nothing else it will help us explain to you what the error means...
    Please do not ask for code as refusal often offends.

    ** This space for rent **

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

    Default Re: How can I add an actionListener to a timer?

    The error is "The method addActionListener() is undefined for the type Timer".

  4. #4
    Zyril is offline Senior Member
    Join Date
    Oct 2011
    Location
    Sweden
    Posts
    124
    Rep Power
    0

    Default Re: How can I add an actionListener to a timer?

    Quote Originally Posted by gregsakas View Post
    The error is "The method addActionListener() is undefined for the type Timer".
    The error is self-explanatory, the method you are trying does not exist.
    What type of Timer object are you creating? There is no method "addActionListener()" for the java.util.Timer, though there is for "javax.swing.Timer".

  5. #5
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,811
    Rep Power
    19

    Default Re: How can I add an actionListener to a timer?

    There isn't one for javax.swing.Timer either.
    Not one that takes no parameters anyway.
    DarrylBurke likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

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

    Default Re: How can I add an actionListener to a timer?

    Quote Originally Posted by Zyril View Post
    The error is self-explanatory, the method you are trying does not exist.
    What type of Timer object are you creating? There is no method "addActionListener()" for the java.util.Timer, though there is for "javax.swing.Timer".
    Thanks!

Similar Threads

  1. Please help with actionlistener
    By ADustedEwok in forum New To Java
    Replies: 5
    Last Post: 12-08-2011, 10:04 PM
  2. Timer And Timer Task
    By Ashish_jain in forum New To Java
    Replies: 3
    Last Post: 06-22-2011, 09:41 AM
  3. Stopping a Timer from Inside the timer
    By krishnan in forum Java Applets
    Replies: 2
    Last Post: 10-04-2010, 11:15 PM
  4. Using ActionListener with a Timer Object
    By bumblyb33 in forum New To Java
    Replies: 2
    Last Post: 03-04-2009, 11:26 PM
  5. Replies: 0
    Last Post: 04-04-2008, 02:46 PM

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
  •