• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can you use 8 counters in one window?

 
Eamon Williams
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • 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 ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!