Witam,
ucząc się javy zrobiłem prostą animacje, która zamiast przesuwać napis nakłada jeden na drugi (nie usuwając poprzedniego napisu) przez co rysuje grubą czarną krechę. Proszę mi powiedzieć co jest nie tak.
import java.awt.*;
import javax.swing.*;
public class Anim extends JFrame{
public static void main(String[] args){
Anim a = new Anim();
a.setVisible(true);
}
public Anim(){
setSize(700,700);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
APane apan = new APane();
getContentPane().add(apan);
}
public class APane extends JPanel implements Runnable{
Thread runner;
int Xpos = 0;
APane()
{
if(runner==null)
{
runner = new Thread(this);
runner.start();
}
}
public void run()
{
while(true)
{
repaint();
try
{
Thread.sleep(20);
}catch(Exception ex){}
}
}
public void stop()
{
if(runner!=null)
{
runner = null;
}
}
@Override
public void paintComponent(Graphics g){
g.drawString("Siema!", Xpos, 100);
Xpos++;
if(Xpos > 500)
Xpos = 0;
}
}
}