You are here: Home / Topics / Program with Banner applet in Java

Program with Banner applet in Java

Filed under: Java on 2023-09-20 06:36:06

// Program with Banner applet.

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

/*
<applet code="Applet03" width="300" height="50">
</applet>
*/

public class  Applet03 extends Applet implements 
Runnable 
{
String msg = "Java Programming Examples";
Thread t = null;
boolean flag;

public void init() 
{
 setBackground(Color.yellow);
 setForeground(Color.red);
}

public void start() 
{
 t = new Thread(this);
 flag = false;
 t.start();
}

public void run() 
{
 char ch;
 for( ; ; ) 
 {
  try 
  {
   repaint();
   Thread.sleep(250);
   ch = msg.charAt(0);
   msg = msg.substring(1, msg.length());
   msg += ch;
   if(flag)
    break;
  } 
  catch(InterruptedException e) 
  { }
 }
}

public void stop() 
{
 flag = true;
 t = null;
}

public void paint(Graphics g) 
{
 g.drawString(msg, 50, 30);
}
}


Output:

 D:\Java>appletviewer Applet03.java

About Author:
S
Shyam Dubey     View Profile
If you are good in any field. Just share your knowledge with others.