my dog learned polymorphism*
The moose likes Beginning Java and the fly likes Timer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Timer" Watch "Timer" New topic
Author

Timer

Antony Amicone
Ranch Hand

Joined: Mar 11, 2006
Posts: 125
why it does not run?it only write "try main"


[ March 30, 2006: Message edited by: Antony Amicone ]
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Havin' a wee spot o' fun?


There is no emoticon for what I am feeling!
Antony Amicone
Ranch Hand

Joined: Mar 11, 2006
Posts: 125
i'm trying to figure out how to use timers...
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
The main method is exiting before the timer has a chance to do anything. Add a delay at the end of the main method, and also remember that Frame's aren't visible by default.
[ March 30, 2006: Message edited by: Keith Lynn ]
Antony Amicone
Ranch Hand

Joined: Mar 11, 2006
Posts: 125
how to add delay at the and of main? if i put the start of timer in the method prova it is not runned anyway
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Antony Amicone
Ranch Hand

Joined: Mar 11, 2006
Posts: 125
tnx a lot, is it impossible without thread?
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Well if you had other activities happening in the main method, that would work too. The problem is that you set the timer so that the actionPerformed method is called every second. When you create the timer, that does not stop the main method from executing. It goes to the next line, and then it is finished. So the main method exits before the first second.

Note that using Thread.sleep does not create a new thread. There is a thread that is running the main method. Whatever thread executes Thread.sleep is the one that will pause.
[ March 30, 2006: Message edited by: Keith Lynn ]
Antony Amicone
Ranch Hand

Joined: Mar 11, 2006
Posts: 125
tnx a lot, u were really gentle, and exhaustive
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Timer