Pages

Java Tutorials

Java Tutorials
Java Tutorials

Wednesday, 6 November 2013

Applet Program of Heart Animation

import java.applet.*;
import java.awt.*;
public class myapplet extends Applet
{
public void init()
{
setBackground(Color.RED);
setForeground(Color.YELLOW);

}
public void paint(Graphics g)
{
int x[]={110,60,10,10,60,110,160,210,210,160,110,110};
int y[]={60,10,60,160,210,160,210,160,60,10,60,160};
g.drawRect(10,10,200,100);
g.drawPolygon(x,y,12);
g.drawArc(10,10,100,100,0,360);
g.fillArc(10,10,100,100,0,360);
}
}
/*
<applet code=myapplet width=400 height=400>
</applet>
*/






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