Saturday, 7 July 2012

program that dispaly rotating banner in applet

import java.awt.*;
import java.applet.*;

/* <applet code="banner" width=300 height=200>
   </applet> */

 public class banner extends Applet implements Runnable 
   {
     Font f;
    String mgs="welcome to applet programming language...";
    Thread t=null;
    int state;
    boolean stopflag;
 public void init()
   {
     f=new Font(mgs,Font.ITALIC|Font.BOLD,30);
    setBackground(Color.red);
    setForeground(Color.black);
    setFont(f);

   }
 public void start()
   {
    t=new Thread(this);
    stopflag=false;
    t.start();
   }
 public void run()
   {
    char ch;
    for(;;)
    {
    try
     {
      repaint();
      Thread.sleep(500);
      ch=mgs.charAt(0);
      mgs=mgs.substring(1,mgs.length());
      mgs +=ch;
      if(stopflag)
        break;
     }catch(InterruptedException e){}
   }
 }
 public void stop()
   {
    stopflag=true;
    t=null;
   }
 public void paint(Graphics g)
   {
    g.drawString(mgs,100,100);
   }
 }