Java applet program to implementing running face
import java.awt.*;
import java.applet.*;
/*
<Applet code="runFace"
height=500
width=500
>
</Applet>
*/
public class runFace extends Applet implements Runnable
{
int h1,h2,h3,h4;
int ley1,ley2,ley3,ley4;
int rey1,rey2,rey3,rey4;
int leyld1,leyld2,leyld3,leyld4;
int reyld1,reyld2,reyld3,reyld4;
int ns1,ns2,ns3,ns4;
int mt1,mt2,mt3,mt4;
int flag;
public void init()
{
h1=40;h2=40;h3=150;h4=150;
ley1=70;ley2=70;ley3=30;ley4=20;
rey1=120;rey2=70;rey3=30;rey4=20;
reyld1=125;reyld2=65;reyld3=150;reyld4=65;
leyld1=70;leyld2=65;leyld3=95;leyld4=65;
mt1=90;mt2=140;mt3=50;mt4=10;
ns1=112;ns2=90;ns3=112;ns4=125;
setBackground(Color.cyan);
}
public void start()
{
flag=1;
Thread t=new Thread(this);
t.start();
}
public void run()
{
for(;;)
{
try
{
if(flag==1)
{
h1++;h2++;
ley1++;ley2++;
rey1++;rey2++;
leyld1++;leyld2++;leyld3++;leyld4++;
reyld1++;reyld2++;reyld3++;reyld4++;
ns1++;ns2++;ns3++;ns4++;
import java.applet.*;
/*
<Applet code="runFace"
height=500
width=500
>
</Applet>
*/
public class runFace extends Applet implements Runnable
{
int h1,h2,h3,h4;
int ley1,ley2,ley3,ley4;
int rey1,rey2,rey3,rey4;
int leyld1,leyld2,leyld3,leyld4;
int reyld1,reyld2,reyld3,reyld4;
int ns1,ns2,ns3,ns4;
int mt1,mt2,mt3,mt4;
int flag;
public void init()
{
h1=40;h2=40;h3=150;h4=150;
ley1=70;ley2=70;ley3=30;ley4=20;
rey1=120;rey2=70;rey3=30;rey4=20;
reyld1=125;reyld2=65;reyld3=150;reyld4=65;
leyld1=70;leyld2=65;leyld3=95;leyld4=65;
mt1=90;mt2=140;mt3=50;mt4=10;
ns1=112;ns2=90;ns3=112;ns4=125;
setBackground(Color.cyan);
}
public void start()
{
flag=1;
Thread t=new Thread(this);
t.start();
}
public void run()
{
for(;;)
{
try
{
if(flag==1)
{
h1++;h2++;
ley1++;ley2++;
rey1++;rey2++;
leyld1++;leyld2++;leyld3++;leyld4++;
reyld1++;reyld2++;reyld3++;reyld4++;
ns1++;ns2++;ns3++;ns4++;
mt1++;mt2++;
if(h1>=345)
flag=0;
}
else
{
h1--;h2--;
ley1--;ley2--;
rey1--;rey2--;
leyld1--;leyld2--;leyld3--;leyld4--;
reyld1--;reyld2--;reyld3--;reyld4--;
ns1--;ns2--;ns3--;ns4--;
mt1--;mt2--;
if(h1<=0)
flag=1;
}
repaint();
Thread.sleep(5);
}
catch(Exception ex)
{
System.out.println(ex.getMessage());
}
}
}
public void paint(Graphics g)
{
g.drawOval(h1,h2,h3,h4);
g.drawOval(ley1,ley2,ley3,ley4);
g.drawOval(rey1,rey2,rey3,rey4);
g.drawLine(leyld1,leyld2,leyld3,leyld4);
g.drawLine(reyld1,reyld2,reyld3,reyld4);
g.drawLine(ns1,ns2,ns3,ns4);
g.drawOval(mt1,mt2,mt3,mt4);
}
}
Output
Running face using java |
No comments:
Post a Comment