• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

timer class

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Message for you sir! I think it is a tiny ad:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic