Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Clock

 
Martin vanPutten
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay... brain fart. I want to make a simple clock. So, I have seconds, minutes, and hous. therefore, in order for it to increase i need the seconds to start off.. (and its digital format) so how do I get the seconds to increase by 1 in exactly 1 second?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use a timer
 
Martin vanPutten
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dah!!! I know how to do that, why didn't i think of that! I really did have a brain fart!!
 
Martin vanPutten
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I havn't done this for a while. I get 4 errors. What am i missing or screwing up on?
 
Martin vanPutten
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nvm, i got it.
 
Martin vanPutten
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now i'm having trouble, can someone help me get it to increment by 1 second.
 
Martin vanPutten
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nvm, got it again!!
 
Martin vanPutten
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
k, now i'm stuck, why isn't it repainting and ridding the previous number?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> why isn't it repainting and ridding the previous number?

you need to include, in paint()
super.paint(g);

as you're using JApplet, it might be a whole lot easier
for you to use a JLabel

 
Martin vanPutten
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I forgot super as well, i shouldn't of stopped doing this, I used to know this stuff, thank!!
 
Martin vanPutten
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why isn't my background black i said it was?

 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try it like this - using swing's paintComponent()

 
Martin vanPutten
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can i set the clock to real time?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SimpleDateFormat to match the pattern you have
then just
g.drawString( sdf.format(new Date()) , 270, 60);
 
Martin vanPutten
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm... I'm confused. Is there more to this?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> Hmm... I'm confused. Is there more to this?

what's confusing? - the code is much simpler now.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic