I am new to applet programming. When I run my code in applet viewer its working, but its not working when I ran it in the browser(It shows a blank white web page) Here is my code.
import java.awt.*;
import java.applet.*;
public class BannerApplet extends Applet implements Runnable
{
String msg= "A simple moving Banner";
Thread t=null;
int state;
boolean stopFlag;
public void init()
{
setBackground(Color.cyan);
setForeground(Color.red);
}
public void start()
{
t=new Thread(this);
stopFlag=false;
t.start();
}
public void run()
{
char ch;
for(int i=0;i<100;i++)
{
try
{
repaint();
Thread.sleep(250);
ch=msg.charAt(0);
msg=msg.substring(1,msg.length());
msg+=ch;
if(stopFlag)
break;
}
catch(InterruptedException e){
}
}
}
public void stop()
{
stopFlag=true;
t=null;
}
public void paint(Graphics g)
{
g.drawString(msg,50,30);
showStatus("this is a message box");
}
}
And here is my html code.
<!DOCTYPE html>
<html>
<title>
applet window
</title>`
<body>
<applet code="BannerApplet.class" width=300 height=100>
</applet>
</body>
</html>