• 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

Clock and text display question

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well, in my program, i want to add a clock to show player left time, and there is a button and a label, after user click the btn, label will show a sentence, after a while, e.g. 1 second, the sentence will be removed and the btn is actived again, so that user can click on it and show next sencence, and things go on.

currently, i use two threads, one is timer, another is textThread, in my run() method, if Thread.currentThread()==timer, i decrease remainTime by 1 and show it, if Thread.currentThread()==textThread, i display the text on the label and then sleep 1 second, but it has no reaction at all. am i on the right way? is there any alternative method?

Cheers.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What GUI package are you using? AWT? SWT? Swing?

Henry
 
David Nelson
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
AWT, anything different in my program? what should i suppose to do if i use Swing.

for the clock thing, i guess the choice is only Thread or Timer, so how about text showing, how can i remove them out after 1 every second.

Cheers.
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

perhaps you could solve your problem like this: when the button is pressed, display your sentence, deactivate the button and start a java.util.Timer. The run()-method of your timer removes the sentence from the label and reactivates the button. Some code snippets:


Stefan
 
David Nelson
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just got the point, thanks a lot
 
reply
    Bookmark Topic Watch Topic
  • New Topic