the following code is vary simple Thread code..
it simply print a string Character by character ... and it sleep between each printing ..
so you will se it printing one by one ..
so simple ... just to clear the idea of Thread
any comment .. just inform me
public class MyThread extends Thread{
private static int ThreadNumber=1;
private int SleepTime;
// construct
public MyThread()
{
super("Thread Number: "+ThreadNumber);
ThreadNumber++;
}// end constructor
// the defult start method----------------------------------------------------
public void run()
{
}// end run method
// to print character by catacter
public void printThread(String text)
{
System.out.print("\n");
for (int i = 0; i < text.length(); i++)
{
try{
Thread.sleep(300);//<- for how long the Thread will sleep
}catch(InterruptedException exception)
{exception.printStackTrace();}
// print
System.out.print(text.charAt(i));
}//end for
}//end method printThread
// the main method--------------------------------------------------------------
public static void main(String[] args) {
System.out.println("\n\n\tStart the main Method:\n");
MyThread t1 = new MyThread();
t1.printThread("The Thread is Printing the String Character by character ... "); //<- enter any string
System.out.print("\n End the Main...");
}//end the main method
}//end class MyThread