File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Timer

 
Antony Amicone
Ranch Hand
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why it does not run?it only write "try main"


[ March 30, 2006: Message edited by: Antony Amicone ]
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Havin' a wee spot o' fun?
 
Antony Amicone
Ranch Hand
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm trying to figure out how to use timers...
 
Keith Lynn
Ranch Hand
Posts: 2399
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2399
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Antony Amicone
Ranch Hand
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
tnx a lot, is it impossible without thread?
 
Keith Lynn
Ranch Hand
Posts: 2399
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
tnx a lot, u were really gentle, and exhaustive
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic