Need help with actionlistener


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Need help with actionlistener

  1. #1
    Join Date
    Jun 2006
    Posts
    1

    Need help with actionlistener - *fixed*

    I figured it out: I forgot to import javax.swing.Timer;.


    I can't figure out what I did wrong here, so I was hoping you guys can help me out:


    The complier said it couldn't find the symbol at "timer = new Timer(1000, new ActionListener()"
    Code:
    Timer timer;
    Tin tin = new Tin();
    //inside a method
    timer = new Timer(1000, new ActionListener()
       {
                public void actionPerformed(ActionEvent evt)
                {
                      if (tin.test() == true)
            		count++;
                }
       });
    Last edited by Louis_8771; 06-10-2006 at 05:34 PM.

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560

    I very rarely use inner classes

    ..so this is the way I would do it, I have commented out the references to Tin & count as I don't know anything about their usage.

    Code:
    import javax.swing.Timer;
    import java.awt.event.*;
    
    public class TimerTest implements ActionListener {
      Timer timer;
      //Tin tin = new Tin();
    
      public TimerTest() {
    
        timer = new Timer(1000, this);
      }
    
      public void actionPerformed(ActionEvent e) {
        //if (tin.test() == true)
        //count++;
      }
    
    }
    eschew obfuscation

Similar Threads

  1. ActionListener problem
    By digital_trex in forum Java
    Replies: 2
    Last Post: 08-31-2005, 01:30 PM
  2. Replies: 2
    Last Post: 07-24-2005, 09:42 AM
  3. Problem in actionListener
    By plan_ever in forum Java
    Replies: 1
    Last Post: 05-25-2005, 12:06 PM
  4. how to add an actionlistener?
    By skippy in forum Java
    Replies: 0
    Last Post: 11-23-2002, 06:51 PM
  5. NullPointerException when reading text file
    By Andrew McLellan in forum Java
    Replies: 3
    Last Post: 05-09-2001, 05:34 PM

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