File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes timer class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "timer class" Watch "timer class" New topic

timer class

Dale Smirth

Joined: May 17, 2005
Posts: 14
I am new to Java programming, but intrigued by the paradigm of the object-oriented concept.

I would like to get some input related to my concept before diving into the actual programming.

Is this possible:

I would like to use the Timer class to trigger random threads. The threads do nothing more than sleep for a random amount of time. The thread then terminates.

I had thought about using a while loop, but I ran across the Timer class and it sounds like it could save me a lot of extra coding.

I would be build around this class defintion:

public class CLASSNAME extends JFrame implements Runnable, ActionListener

This line would use the Runnable interface for threads and use the ActionListener interface for event handling for my gui.

Am I off to a good start?


BTW, any input on the implementing the Timer class would be appreciated.
Dhruv Shah

Joined: May 02, 2005
Posts: 19
The use of Timer class is as this

1. Create the TimerTask. i.e. you extend this class to implement your own task which needs to be done (at/after specific time)

2. Create instance of Timer and then use above task

Hope this helps!

fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11952

DMa xJ,

I'm betting that you will shortly be asked by a sherrif/bartender to change your name. The policy here is that you must use a real (sounding) first and last name (although i think a first initial is allowed).

The policy is stated here, and you can change your name here.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Dale Smirth

Joined: May 17, 2005
Posts: 14
Okay, I think that I am on the right track.

Whats wrong with this line?

public class CLASSNAME extends JFrame, TimerTask implements ActionListener, Runnable

I am more interested in extending the TimerTask but my code triggers lots of 'cannot resolve symbol' when I remove JFrame.

How could I fix this problem. I need to be able to extend JFrame and TimerTask.

I agree. Here's the link:
subject: timer class
It's not a secret anymore!