Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Conrad Evans   on Jul 06 In Java Category.

  
Question Answered By: Jonathan Harrison   on Jul 06

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();
}
}

Share: 

 

This Question has 1 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Repaint the screen in a for loop Or get search suggestion and latest updates.


Tagged: