We have to import java.applet.* and java.awt.* package. This program done by the Thread. But as we already extends Applet class, we cannot extends another class called Thread. But we can implements the Runnable interface. Now initialised the thread object in init() method and start it in start() method. now overload the run() method to exchange the string and display it every 1 second. repaint() method is used to recall the paint() method with the new set of variables values.
import java.awt.*; import java.applet.*; public class App1 extends Applet implements Runnable { String msg; Thread th; public void init() { msg="Hello World"; th=new Thread(this); } public void start(){ th.start(); } public void paint(Graphics g){g.drawString(msg,100,200);} public void run() { while(true) { if(msg.equals("Hello World")) { msg=""; } else { msg="Hello World"; } try{Thread.sleep(1000);} catch(Exception e){} repaint(); } } }