• Post Reply Bookmark Topic Watch Topic
  • New Topic

add timer to jframe

 
yashar nesabian
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i`m trying to write a game which needs timer beginning from zero to.... , and show it in my jframe
how can i do that?
thanks
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
 
Campbell Ritchie
Marshal
Posts: 52581
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't show a Timer. You use it to signal events. You should have some classes for the logic of your game, and use the Swing classes simply for displaying things.
By the way: there are at least three classes called Timer. You probably want this one.
 
yashar nesabian
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:You don't show a Timer. You use it to signal events. You should have some classes for the logic of your game, and use the Swing classes simply for displaying things.
By the way: there are at least three classes called Timer. You probably want this one.


i`m a bit confused i can`t understand what you mean(You use it to signal events) i want timer to count the time
can you show me an example?
thanks
 
Rob Camick
Ranch Hand
Posts: 2700
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When a user clicks on a button you write an ActionListener to do something.

So when a Timer generates an event you write an ActionListener to do something.

Here is my simple example that simply displays the time.

 
Campbell Ritchie
Marshal
Posts: 52581
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A Timer does not act as a clock recording how long something has been going on for.
It acts as an alarm; as Rob Camick has shown you, it causes something to happen at predetermined intervals.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!