 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Poochie Guest
|
Posted: Fri Jun 25, 2004 12:40 am Post subject: Sleep in Java |
|
|
How can I tell my program to sleep for a number of milliseconds and then go
for the next instruction?
Thanks, Poochie
|
|
| Back to top |
|
 |
Roedy Green Guest
|
|
| Back to top |
|
 |
Xavier Tarrago Guest
|
Posted: Fri Jun 25, 2004 7:23 am Post subject: Re: Sleep in Java |
|
|
Is it a joke ???
It would be nice if to tell a thread to sleep for a number of millis, you
had to call a method sleep on the thread Class, passing as an argument the
number of millis!
"Poochie" <poochie2NO_SPAM (AT) libero (DOT) it> a écrit dans le message de
news:1b8ymc1mcja8t.1e89ky1k6xqe3.dlg (AT) 40tude (DOT) net...
| Quote: | How can I tell my program to sleep for a number of milliseconds and then
go
for the next instruction?
Thanks, Poochie
|
|
|
| Back to top |
|
 |
Yu SONG Guest
|
Posted: Fri Jun 25, 2004 2:22 pm Post subject: Re: Sleep in Java |
|
|
Poochie wrote:
| Quote: | How can I tell my program to sleep for a number of milliseconds and then go
for the next instruction?
Thanks, Poochie
|
Use threads...
--
Song
/* E-mail.c */
#define User "Yu.Song"
#define Warwick "warwick.ac.uk"
int main() {
printf("Yu Song's E-mail: %s@%s", User, Warwick);
return 0;}
Further Info. : http://www.dcs.warwick.ac.uk/~esubbn/
_______________________________________________________
|
|
| Back to top |
|
 |
Poochie Guest
|
Posted: Fri Jun 25, 2004 10:05 pm Post subject: Re: Sleep in Java |
|
|
Anno domini Fri, 25 Jun 2004 00:40:35 GMT, Poochie, nobilissimus apud
internautas, scripsit:
[CUT]
That might be what I needed, but I get this:
"JFrameMain.java": unreported exception java.lang.InterruptedException;
must be caught or declared to be thrown at line 279, column 17
What I must do is simply wait a second to let the user see the situation I
drew on a JPanel and then redraw for n times... maybe should I first get
the current thread?
Please help,
Poochie©
|
|
| Back to top |
|
 |
Roedy Green Guest
|
Posted: Fri Jun 25, 2004 10:06 pm Post subject: Re: Sleep in Java |
|
|
On Fri, 25 Jun 2004 22:05:10 GMT, Poochie <poochie2NO_SPAM (AT) libero (DOT) it>
wrote or quoted :
| Quote: | That might be what I needed, but I get this:
"JFrameMain.java": unreported exception java.lang.InterruptedException;
must be caught or declared to be thrown at line 279, column 17
What I must do is simply wait a second to let the user see the situation I
drew on a JPanel and then redraw for n times... maybe should I first get
the current thread?
|
What you should do is read the links provided you that answer the
usual questions.
Again, see http://mindprod.com/jgloss/sleep.html
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
|
|
| Back to top |
|
 |
Poochie Guest
|
Posted: Fri Jun 25, 2004 10:25 pm Post subject: Re: Sleep in Java |
|
|
Anno domini Fri, 25 Jun 2004 22:06:44 GMT, Roedy Green, nobilissimus apud
internautas, scripsit:
Actually that's what I did, but I'm getting an error and I cannot see the
reason...
Writing
Thread.sleep(1000);
will result in the error I reported and be underlined in red in JBuilder,
so something's wrong, and that's what I'm puzzled about!
Poochie©
|
|
| Back to top |
|
 |
Poochie Guest
|
Posted: Fri Jun 25, 2004 10:30 pm Post subject: Re: Sleep in Java |
|
|
Anno domini Fri, 25 Jun 2004 22:25:47 GMT, Poochie, nobilissimus apud
internautas, scripsit:
[CUT]
Now I got it working, the problem was that I simply had no idea that a
method could refuse to work because I set no CATCH, at most I thought it
could give an exception...
|
|
| Back to top |
|
 |
Roedy Green Guest
|
Posted: Fri Jun 25, 2004 10:41 pm Post subject: Re: Sleep in Java |
|
|
On Fri, 25 Jun 2004 22:25:47 GMT, Poochie <poochie2NO_SPAM (AT) libero (DOT) it>
wrote or quoted :
Read the entry again. It has mutated, like the Borg, adapting to your
new assaults on Java.
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
|
|
| Back to top |
|
 |
Chris Smith Guest
|
Posted: Fri Jun 25, 2004 11:08 pm Post subject: Re: Sleep in Java |
|
|
Poochie wrote:
| Quote: | Now I got it working, the problem was that I simply had no idea that a
method could refuse to work because I set no CATCH, at most I thought it
could give an exception...
|
Well, sort of. It can just give an exception, but Java requires that
you acknowledge the possibility of an exception arising from any
dangerous action. InterruptedException is one of the places where it
makes the least possible sense, though, since it represents a
programming bug for a thread to be interrupted when it wasn't expected.
Nevertheless, InterruptedException was classified as a checked
exception, so you have to abide by the rules.
You don't have to catch the exception, though. Your other alternative
is to declare it in a throws clause in the method declaration, to
indicate you don't intend to handle the exception here and it should be
passed on.
--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|