Tuesday, 2 September 2014

Java Applet Program To Display Animated Heart

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

public class Heart extends Applet
{
int x=0;
public void paint(Graphics g)
{

if(x==0)
{
setBackground(Color.orange);
int a[]={50,300,300};
int b[]={175,175,550};

g.setColor(Color.red);

g.fillArc(50,50,250,250,0,180);
g.fillPolygon(a,b,3);
}

if(x==1)
{
setBackground(Color.yellow);
int a[]={550,300,300};
int b[]={175,175,550};

g.setColor(Color.red);

g.fillArc(300,50,250,250,0,180);
g.fillPolygon(a,b,3);
}

if(x==2)
{
setBackground(Color.green);
int a[]={50,550,300};
int b[]={175,175,550};

g.setColor(Color.red);

g.fillArc(50,50,250,250,0,180);
g.fillArc(300,50,250,250,0,180);
g.fillPolygon(a,b,3);

x=0;
}

else
x=x+1;
try
{
Thread.sleep(500);
repaint();
}
catch(Exception e)
{
}
}
}
/*
<applet code=Heart width=600 height=600>
</applet>
*/

No comments:

Post a Comment