Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

timer class

 
Dale Smirth
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

Thanks

BTW, any input on the implementing the Timer class would be appreciated.
 
Dhruv Shah
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!


Thanks

www.indianuncle.com
 
fred rosenberger
lowercase baba
Bartender
Posts: 12126
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

thanks!!!
 
Dale Smirth
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, I think that I am on the right track.

Whats wrong with this line?


public class CLASSNAME extends JFrame, TimerTask implements ActionListener, Runnable
{
//constructor
}

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.

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic