Search This Blog

Saturday, November 20, 2010

Moving Banner in Swing

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;



public class MovingBanner1 extends JApplet implements Runnable
  {
  
/*<Applet code="MovingBanner1.class" height=50 width=250>
   </Applet>
*/
String s;
JLabel lbl;
public void init()
  {
  
  
     Container frame = getContentPane();
      frame.setLayout(new BorderLayout());
        lbl = new JLabel("Welcome to My Blog -*- ");
          lbl.setFont(new Font("Helvetica", Font.BOLD, 20));
           lbl.setForeground(Color.blue);
        frame.add(lbl, BorderLayout.CENTER);

  
   s= "Welcome to My Blog -*- ";
 
 
  }
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;
       lbl.setText(s);
      
      
      Thread.sleep(200);
           }
       catch(InterruptedException e)
        {}
    
      }
}
}

0 comments:

Post a Comment