Welcome to Dream.In.Code
Become a Java Expert!

Join 149,609 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,864 people online right now. Registration is fast and FREE... Join Now!




A way to delay output

 
Reply to this topicStart new topic

A way to delay output, I'm just asking if there is a way

Mastergeek666
17 Sep, 2007 - 09:39 AM
Post #1

D.I.C Head
Group Icon

Joined: 10 Aug, 2007
Posts: 120


Dream Kudos: 75
My Contributions
I was wondering if there is a way to for example:
CODE
System.out.println ("Text")
then have the output of another text be delayed for a sec then do the next "System.out.println..." If anyone could shed some light that would be great.

User is offlineProfile CardPM
+Quote Post

1lacca
RE: A Way To Delay Output
17 Sep, 2007 - 09:45 AM
Post #2

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 12 times
My Contributions
Have a look at the Thread class.
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: A Way To Delay Output
17 Sep, 2007 - 09:48 AM
Post #3

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,655



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
You could put the thread to sleep for a number of seconds. Using a thread sleep though will require you to also put it in a try catch to catch an InterruptedException. Otherwise Java will throw a fit that you are not catching this. Here is a great example for you...

sleeptest.java

CODE

public class sleeptest {
    public static void main(String args[]) {

        // Print the first part
        System.out.println("hello");

        // Put the thread to sleep for 3 seconds
        try {
            Thread.sleep(3000);
        }
        catch (InterruptedException ex)
        {
            // do nothing
        }

        // Print second part
        System.out.println("there");

    }
}


Enjoy! decap.gif
User is offlineProfile CardPM
+Quote Post

1lacca
RE: A Way To Delay Output
17 Sep, 2007 - 10:02 AM
Post #4

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 12 times
My Contributions
Lol, looks like Martyr2 did the digging for you!
User is offlineProfile CardPM
+Quote Post

Mastergeek666
RE: A Way To Delay Output
17 Sep, 2007 - 10:08 AM
Post #5

D.I.C Head
Group Icon

Joined: 10 Aug, 2007
Posts: 120


Dream Kudos: 75
My Contributions
Thanks this is exactly what I needed to make my program more, fun. Thanks again!
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: A Way To Delay Output
17 Sep, 2007 - 10:15 AM
Post #6

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,655



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
*Martyr pops his head out of the hole he is digging, head lamp on his helmet and all*

I find all kinds of junk when I dig. Just last week I found an old rusty version of system("pause"); but since it was platform specific I threw it away. And this other time I found a function for encryption only to find out that it simply made the words into pig-latin. So I had to toss that one too.

Once in awhile I find a good solution and can pass it on in the market and get rich knowing that I helped out somebody with their program.

smile.gif
User is offlineProfile CardPM
+Quote Post

Mastergeek666
RE: A Way To Delay Output
18 Sep, 2007 - 06:21 PM
Post #7

D.I.C Head
Group Icon

Joined: 10 Aug, 2007
Posts: 120


Dream Kudos: 75
My Contributions
Much Obliged!
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 12:14AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month