/*
<applet
code="BouncingWords" width="200" height="200">
</applet>*/
import
java.io.*;
import
java.applet.*;
import
java.awt.*;
public
class BouncingWords extends Applet
{
static
int i=0,j=1200,flag=0;
Thread
th=new Thread(); //Defining Thread.
public
void paint(Graphics g)
{
if(flag==0)
{
if(i!=j)
{
i++;
j--;
}
else
flag=1;
}
else
{
if(i!=0&&j!=1200)
{
i--;
j++;
}
else
flag=0;
}
g.drawString("Nothing
is ",i,200); //Calling drawstring function
g.drawString("Impossible",j,350);
try
{
th.sleep(5);
}
catch (Exception e)
{
}
repaint();
//Calling repaint method.
}
}
Output:
C:\>javac
BouncingWords.java
C:\>appletviewer
BouncingWords.java
This blog is really informative i really had fun reading it.
ReplyDelete