2 Dec 2013

implementation of banner animation in java applet code

/* scrolling of given message using threads in java applet code, implementation of banner animation in java applet code, program to display moving banner in java code */

import java.awt.*;
import java.applet.*;
/*
<applet code="animation" width="300" height="200">
</applet>
*/
public class animation extends Applet implements java.lang.Runnable
{
String msg=" Welcome to Java";
public void init()
{
setBackground(Color.yellow);
setForeground(Color.red);
}
public void Start()
{
Thread t=new Thread(this);
//this refers to the current class object.
t.start();
}
public void paint(Graphics g)
{
Font f=new Font("Arial",Font.BOLD,20);
g.setFont(f);
System.out.println("msg: "+msg);
g.drawString(msg,100,100);
}
public void run()
{
while(true)
{
try
{
char ch=msg.charAt(0);
msg=msg.substring(1,msg.length());
msg=msg+ch;
repaint();
java.lang.Thread.sleep(100);
}
catch (java.lang.Exception e)
{
e.printStackTrace();
}
}//while
}//run()
}//class


How to run:
javac ani.java
appletviewer ani.java


Output:


implementation of banner animation in java applet code

0 comments:

Post a Comment