Okay… Im using the following class (minus the constants string value with the full text) to attempt to create text that displays on the screen in a time delayed way per character(video game wonderment) and in trying to pause it I attempted to create a thread that then caused my top 4 lines to keep creating the class and a stack overflow emerged.
Question… given my code below. What do i need to do to make the thread without stack overflowing and pause the text and end the thread.
After much Googling i am very confused on this subject.
public class TextDelay extends Applet implements Runnable{
private String screenMessage = ""; //stars empty
private int messagePos = 0;
// Create the object with the run() method
Runnable runnable = new TextDelay();
// Create the thread supplying it with the runnable object
Thread thread = new Thread(runnable);
private boolean allDone = false;
public void run() {
// Start the thread
thread.start();
}
public void paint ( Graphics g )
{
// update the message
while (messagePos != ConstantsT.message.length()){
try {
long numMillisecondsToSleep = 1000; // 1 seconds
Thread.sleep(numMillisecondsToSleep);
} catch (InterruptedException e) {
}
screenMessage = screenMessage + ConstantsT.message.charAt(messagePos);
messagePos++;
if (messagePos == ConstantsT.message.length()){
//thread.allDone = true ;
break;
}
}
//End of message.
g.setColor ( Color.blue );
g.drawString ( screenMessage, 10 , 10 );
}
}
