Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / June 2004

Tip: Looking for answers? Try searching our database.

Sleep in Java

Thread view: 
Poochie - 25 Jun 2004 01:40 GMT
How can I tell my program to sleep for a number of milliseconds and then go
for the next instruction?

Thanks, Poochie
Roedy Green - 25 Jun 2004 05:33 GMT
>How can I tell my program to sleep for a number of milliseconds and then go
>for the next instruction?

See http://mindprod.com/jgloss/gettingstarted.html

You need some basic docs to get you started.

See http://mindprod.com/jgloss/sleep.html

Signature

Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.

Xavier Tarrago - 25 Jun 2004 08:23 GMT
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!

> How can I tell my program to sleep for a number of milliseconds and then go
> for the next instruction?
>
> Thanks, Poochie
Yu SONG - 25 Jun 2004 15:22 GMT
> How can I tell my program to sleep for a number of milliseconds and then go
> for the next instruction?
>
> Thanks, Poochie

Use threads...

Signature

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/
_______________________________________________________

Poochie - 25 Jun 2004 23:05 GMT
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©
Roedy Green - 25 Jun 2004 23:06 GMT
>That might be what I needed, but I get this:
>
[quoted text clipped - 4 lines]
>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

Signature

Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.

Poochie - 25 Jun 2004 23:25 GMT
Anno domini Fri, 25 Jun 2004 22:06:44 GMT, Roedy Green, nobilissimus apud
internautas, scripsit:

> http://mindprod.com/jgloss/sleep.html

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©
Poochie - 25 Jun 2004 23:30 GMT
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...
Chris Smith - 26 Jun 2004 00:08 GMT
> 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.

Signature

www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Roedy Green - 25 Jun 2004 23:41 GMT
>> http://mindprod.com/jgloss/sleep.html
>
>Actually that's what I did, but I'm getting an error and I cannot see the
>reason...

Read the entry again. It has mutated, like the Borg, adapting to your
new assaults on Java.

Signature

Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.