Trtld
Trtld

Reputation: 11

Java Timer Error

I have just recently been learning about Java Timers, but I have been having a problem actually using them.
Before I begin to dive deeper into learning about GUI programming, I would like to fully understand Java Timers, being as important as they are.
So far I have two separate classes, a listener class and a main class.
The main class is where I get the error in Eclipse.

package TimTest;

import java.util.Timer;

public class TimerTest  {

    public static void main(String[] args) {

        TimList listener = new TimList();

        Timer timer;
        timer = new Timer(2000, listener );
        timer.start()   
    }
}

And here is the listener class:

package TimTest;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class TimList implements ActionListener{

    public void actionPerformed(ActionEvent evt) {
        System.out.println("TiMeR-TeSt");       
    }
}

So my question is, what am I doing wrong?
As far as I can see everything is done correctly.

Upvotes: 1

Views: 1147

Answers (2)

user2575725
user2575725

Reputation:

You are missing semi-colon here:

timer.start();
             ^ expected here `;`

As per posted image, you need swing timer instead of util, change your import for Timer to:

import java.swing.Timer;

Upvotes: 1

Tilak Madichetti
Tilak Madichetti

Reputation: 4346

Yeah , you need to end the line

   timer.start() 

with a semi-colon ,then it changes to -->

  timer.start();

Upvotes: 1

Related Questions