Special Effects and Game Development
in Java(TM) - The Applet StatusDataText
import java.applet.*;
import java.awt.*;
public class statusdatatext extends Applet implements Runnable {
public Thread animationthread = null;
public String message;
public void init()
{
message="Preparing to launch....";
message+="6... 5... 4... 3... 2... 1... 0...";
}
public void start()
{
if (animationthread == null)
{
animationthread = new Thread(this,"animationthread");
animationthread.start();
}
}
public void stop()
{
if ((animationthread != null) && animationthread.isAlive())
animationthread.stop();
animationthread = null;
}
public void run() { int L=message.length(); boolean showcursor=false; //Write the message step by step with
//the blinking cursor.
for (int i=0; i<L; i++)
{
if (showcursor) showStatus(message.substring(0,i)+"_");
else showStatus(message.substring(0,i));
showcursor=!showcursor;
try {Thread.sleep(100);}
catch(InterruptedException e) {}
}
//The message is written. Animate the cursor
//(keep it blinking).
while (true)
{
if (showcursor) showStatus(message+"_");
else showStatus(message);
showcursor=!showcursor;
try {Thread.sleep(100);}
catch(InterruptedException e) {}
}
}
} |
 |  |
|