Search This Blog

Saturday, November 20, 2010

Moving Banner in Swing

/*********************
 *Program by Kashid
 *Created on July 2005
 *********************/
 import java.awt.*;
import java.awt.Font;
import java.applet.*;
import java.awt.event.*;
/*<applet code="MovingBanner.class" height=50 width=250>
   </applet>
*/

public class MovingBanner extends Applet implements Runnable
  {
     String s;
     Font f;
public void init()
  {
   s= "Welcome to My Blog -*- ";
   f=new Font("Helvetica",1,16); //Font name,Bold=1,size=16
   setFont(f);
   setForeground(Color.red);
  }
public void start()
  {
Thread t=new Thread(this);
t.start();
}



public void run()
  {
   for(;;)
      {
      
      try{
      char c=s.charAt(0);      
       s=s.substring(1)+c;
       repaint();
      Thread.sleep(200);
           }
       catch(InterruptedException e)
        {}
    
      }
}
public  void paint(Graphics g)
{
  g.drawString(s,20,20);
 }


}

1 comments:

Enrico Abordo said...

how to run this code without main?

Post a Comment