try to execute this program....
import java.awt.*;
import java.awt.event.*;
class Face extends Frame implements Runnable
{
int x=0,direction=0;
Face()
{
setSize(300,300);
setVisible(true);
}
public void paint(Graphics g)
{
g.setColor(Color.blue);
g.fillOval(70+x,90+x,140+x,100+x);
g.setColor(Color.red);
g.fillOval(100+x,120+x,20+x,20+x);
g.setColor(Color.red);
g.fillOval(165+x,120+x,20+x,20+x);
}
public void run()
{
while(true)
{
if(direction==0)
{
x++;
if(x==100)
{
direction=1;
}
}
else if(direction==1)
{
x--;
if(x==0)
{
direction=0;
}
}
repaint();
try
{
Thread.sleep(100);
}
catch(Exception e)
{
}
}
}
public static void main(String args[])
{
Face obj = new Face();
Thread t = new Thread(obj);
t.start();
}
}