Hi, I am sending a oval shaped ball across a screen and use the repaint() method controlled by a timer to move it.
public class Court extends JFrame implements Runnable
{
private int x = 10;
private int y = 200;
private int r = 3;
/** Creates new form MainContainer */
public Court()
{
this.setBackground(Color.BLACK);
this.setVisible(true);
start();
}
public void run()
{
while(true)
{
x++;
repaint();
//this.paint(this.getGraphics());
try
{
Thread.sleep(10);
}
catch (InterruptedException ex)
{
}
}
}
public void start()
{
Thread thread = new Thread(this);
thread.start();
}
void p(Graphics g)
{
super.paintComponents(g);
}
public void paint(Graphics g)
{
g.setColor(Color.GREEN);
g.fillOval(x-r, y-r, 2*r, 2*r);
}
}
The green ball does move across the screen but draws a line in its wake. Only when I resize the window does the wake vanish.
Is there something new? I have seen suggestions of a revalidate() method but that method does not seem to exist.
Any help would be welcome.
Many thanks