wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Clock Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Clock" Watch "Clock" New topic
Author

Clock

Martin vanPutten
Ranch Hand

Joined: Mar 26, 2006
Posts: 124
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?


Live And Let Learn.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
use a timer
Martin vanPutten
Ranch Hand

Joined: Mar 26, 2006
Posts: 124
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

Joined: Mar 26, 2006
Posts: 124
I havn't done this for a while. I get 4 errors. What am i missing or screwing up on?
Martin vanPutten
Ranch Hand

Joined: Mar 26, 2006
Posts: 124
nvm, i got it.
Martin vanPutten
Ranch Hand

Joined: Mar 26, 2006
Posts: 124
Now i'm having trouble, can someone help me get it to increment by 1 second.
Martin vanPutten
Ranch Hand

Joined: Mar 26, 2006
Posts: 124
nvm, got it again!!
Martin vanPutten
Ranch Hand

Joined: Mar 26, 2006
Posts: 124
k, now i'm stuck, why isn't it repainting and ridding the previous number?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> 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

Joined: Mar 26, 2006
Posts: 124
I forgot super as well, i shouldn't of stopped doing this, I used to know this stuff, thank!!
Martin vanPutten
Ranch Hand

Joined: Mar 26, 2006
Posts: 124
why isn't my background black i said it was?

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
try it like this - using swing's paintComponent()

Martin vanPutten
Ranch Hand

Joined: Mar 26, 2006
Posts: 124
How can i set the clock to real time?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
SimpleDateFormat to match the pattern you have
then just
g.drawString( sdf.format(new Date()) , 270, 60);
Martin vanPutten
Ranch Hand

Joined: Mar 26, 2006
Posts: 124
Hmm... I'm confused. Is there more to this?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> Hmm... I'm confused. Is there more to this?

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

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Clock