This is my applet code for a moving banner .It is working properly but there is one doubt .
import java.applet.*;
import java.awt.*;
/*<html>
<applet code ="SimpleBanner" width="2000" height="2000"></applet></html>*/
public class SimpleBanner extends Applet implements Runnable{
String msg=" A Simple Banner Is Moving";
boolean flag=false;
Font f=new Font("TimesRoman",Font.BOLD,50);
int i=10;
public void init()
{
setBackground(Color.gray);
setFont(f);
setForeground(Color.green);
}
public void start()
{
Thread t=new Thread(this);
t.start();
}
public void run()
{
for(;;)
{
try{
repaint();
if(flag)
break;
Thread.sleep(250);
}catch(InterruptedException e){}
}
}
public void paint(Graphics g)
{
char ch=msg.charAt(0);
msg=msg.substring(1,msg.length());
msg+=ch;
drawString(msg,300,100);
}
public void stop()
{
flag=true;
}
}
As you can see I am not extending Graphics
class and I am using setFont()
method defined in Graphics
class without its object how this is possible? And if I try to call drawString()
method in paint()
method without g
it is not working.