A simple applet that displays a banner.
The text is placed inside variable msg
import java.awt.*;
import java.applet.*;
/*
<applet code="banner" width = 300 height = 50>
</applet>
*/
public class banner extends Applet implements Runnable{
String msg = " Java";
Thread t = null;
int state;
boolean stopFlag;
public void init(){
setBackground(Color.cyan);
setForeground(Color.red);
}
public void start(){
t = new Thread(this);
stopFlag = false;
t.start();
}
public void run(){
char ch;
for( ; ; ){
try {
repaint();
Thread.sleep(250);
ch = msg.charAt(0);
int j = msg.length();
msg = msg.substring(1, j);
msg += ch;
if(stopFlag)
break;
}
catch(InterruptedException e){}
}
}
public void stop(){
stopFlag = true;
t = null;
}
public void paint(Graphics g){
g.drawString(msg, 50,30);
}
}
Compile as javac banner.java
Run as appletviewer banner.java
Tags:banner in java,java banner,applet,applet in java,java banner applet
- Blogger Comment
- Facebook Comment
Subscribe to:
Post Comments
(
Atom
)
0 comments:
Post a Comment