This is code for, a smiley have to move on the screen from one place to another. But in this code Smiley create but it is moving. Please tell my? Is there any wrong in my code.
import javax.swing.*;
import java.awt.*;
class CreateSmiley extends JPanel
{
int x = 0,y = 0;
public void paintComponen(Graphics g)
{
//System.out.println("x = :"+x);
g.setColor(Color.RED);
g.drawOval(x,y,200,200);
g.setColor(Color.YELLOW);
g.fillOval(x+50,y+70,20,20);
g.fillOval(x+130,y+70,20,20);
g.setColor(Color.GREEN);
g.fillArc(x+30,y+80,140,70,190,165);
//System.out.println("XXX ="+x);
}
void smileFlow() throws Exception
{
CreateSmiley s1 = new CreateSmiley();
while(x != 600)
{
Thread.sleep(100);
x = x + 5;
y = y + 5;
System.out.println("x123 = :"+x);
s1.repaint();
System.out.println("x321 = :"+x);
}
}
}
public class Smiley
{
public static void main(String a[]) throws Exception
{
JFrame f = new JFrame("Smiley");
CreateSmiley s = new CreateSmiley();
s.smileFlow();
// SmileyFlow sf = new SmileyFlow();
f.add(s);
f.setSize(600,600);
f.setVisible(true);
f.setDefaultCloseOperation(3);
}
}