JAVA problem

Questions about programming languages and debugging
Post Reply
User avatar
4rc4ng3L
forum buddy
forum buddy
Posts: 14
Joined: 20 Aug 2005, 16:00
18

JAVA problem

Post by 4rc4ng3L »

Hey guys, got a question about Java(not javascript).
Is it possible for me to delay the output of a string or char. So for example you run the program and each position in the string is displayed with like a 0.5 second wait after the previous position.

Its for a program in which the user can have a conversation with the program itself, that will be the overall function of the program. So a nice fancy delayed output for what the program syas to you would be a nice little touch.

Cheers
Death is the only true freedom, brought on by our own ignorance.... Welcome to the "free" world in which we live...

User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
19
Location: In your eye floaters.
Contact:

Post by bad_brain »

it´s pretty simple by using the sleep()-method to pause the thread:
http://java.sun.com/j2se/1.3/docs/api/j ... hread.html (in the method summary).

here´s a simple example:

Code: Select all

public class TSleep extends Thread{
public static void main(String argv[]){
       TSleep t = new TSleep();
       t.start();
       }
      public void run(){
          try{
             while(true){
                  this.sleep(500);
                  System.out.println("looping while");
                 }
            }catch(InterruptedException ie){}
       }
}
:wink:

User avatar
Nerdz
The Architect
The Architect
Posts: 1127
Joined: 15 Jun 2005, 16:00
18
Location: #db_error in: select usr.location from sucko_member where usr.id=63;
Contact:

Post by Nerdz »

Beurk! while(true) yark yark yark....
Give a man a fish, you feed him for one day.
Learn a man to fish, you feed him for life.

User avatar
4rc4ng3L
forum buddy
forum buddy
Posts: 14
Joined: 20 Aug 2005, 16:00
18

Post by 4rc4ng3L »

cheers
Death is the only true freedom, brought on by our own ignorance.... Welcome to the "free" world in which we live...

Post Reply