I’ve been lurking around various websites and reading up on many different threads over the past few days and I noticed that a few people were saying not to use Thread.sleep for various reasons that I can’t currently remember.
I was wondering if it’s alright to be using Thread.sleep() in this circumstance:
class MessageDisplay
{
public MessageDisplay()
{
}
//NOTE: You may need to add a way to decide where to print the message or else this wont work!
public void typeWriterDisplay(String x, int y) //Requires a string to display and an int to decide how long to wait between displaying letters.
{
for (int i = 0; i < x.length(); i++)
{
System.out.print( x.charAt(i) );
try
{
Thread.sleep(y);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
}
I’m using it to display strings character-by-character with a small delay between characters.