• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Clock and text display question

 
David Nelson
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • 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.
 
Henry Wong
author
Marshal
Pie
Posts: 20881
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Stefan Krompass
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Just got the point, thanks a lot
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic