Saturday, 17 October 2015

Filled Under:

Moving Text Animation In Applet

By using applet you can also create a simple animation program like as we have created in this program.In this we have shown yoy how text can be animated using applet.

HTML CODING:

<html>
<body>
<applet code="myapp" width="300" height="300">
</applet>
</body>
</html>

JAVA CODING:

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

public class myapp extends Applet implements Runnable {
String msg="PRO JAVA TRICKS. ";
char ch;
boolean  stopFlag= true;
Thread t= null;

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

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

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


public void paint(Graphics g)
{
Font f= new Font("forte",Font.ITALIC,36);
g.setFont(f);
g.drawString(msg,220,350);
Color c2 = new Color(52,137,137);
setBackground(c2);
}

}

OUTPUT:



1 comments: