• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can you use 8 counters in one window?

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Could somebody please suggest a way to incorporate up to 8 "counters" (numerical digits counting up) on a Jpanel in a window. I also need to have start/pause/stop JButton control over each counter. Each counter needs to work independently of the others, they may be started/stopped at different times.

I have looked into Timer and TimerTask but unsure how to implement my requirements as above. Also, many counter code examples I have found are applets, which are no good.

Also, is it possible to create a seperate Counter class that will handle the functionality of the timer and update the Jlabel present on the main form class? I am trying to keep as much code out of the main form as possible as it's getting quite big.

Any help gratefully appreciated.

Cheers.
[ February 26, 2006: Message edited by: Eamon Williams ]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Eamon Williams:
Also, many counter code examples I have found are applets, which are no good.

Also, is it possible to create a seperate Counter class that will handle the functionality of the timer and update the Jlabel present on the main form class? I am trying to keep as much code out of the main form as possible as it's getting quite big.

Any help gratefully appreciated.



The fact that a particular GUI example is presented in applet form shouldn't be a problem at all. There's really nothing magic about applets. As long as you know that the container will call init(), then start(), it's very easy to adapt an applet example to be used in other contexts.

As to creating a separate counter component -- yes, absolutely. You could just extend JLabel with an appropriate constructor, a Thread or Swing Timer member, and a few extra methods for starting, stopping, and resetting.
 
Eamon Williams
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great, thanks for the reply. Do you have an example of how to extend a jlabel with a constructor? Would keeping the counter class functionality separate be a cleaner way of maintaining 8 counters on a GUI?

Thanks for the help
 
reply
    Bookmark Topic Watch Topic
  • New Topic