hi frnds... here is a simple animation code which runs but does not show the circle on screen moving.....please help
import javax.swing.*;
import java.awt.*;
public class SimpleAnimation1
{
int x = 70 ; int y = 70;
public static void main(
String[] args)
{
SimpleAnimation1 gui = new SimpleAnimation1();
gui.go();
}
public void go()
{
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
MyDrawpanel drawpanel = new MyDrawpanel();
frame.getContentPane().add(drawpanel);
frame.setSize(300,300);
frame.setVisible(true);
for(int i = 0; i < 130; i++)
{
x++; y++;
drawpanel.repaint();
try
{
Thread.sleep(20);//will know the meaning later
}catch (Exception ex){ }
}
}
class MyDrawpanel extends JPanel//an inner class ( nested class)
{
public void paintCompnent(Graphics g)
{
g.setColor(Color.white);
g.fillRect(0,0,this.getWidth(),this.getHeight());//will replace the green with white
g.setColor(Color.green);
g.fillOval(x,y,40,90);
}
}
}