I am learning about threads and I ran into a problem. My source code is below. I created a simple app to display a series of numbers, one after the other. It works but it doesn't clear the window before the next number is painted. I am using the repaint() method. If I convert the app to awt, that is extend Frame instead of JFrame, and a few other changes to get rid of swing, it works properly. I have no clue as to why this is? Is there a different method to call to achieve these results?<br><br>fenris<br>=================================================<br><br>import java.awt.*;<br>import java.awt.event.*;<br>import javax.swing.*;<br>import javax.swing.event.*;<br><br>public class ThreadTest extends JFrame implements Runnable<br>{<br> Font theFont = new Font("TimesRoman",Font.BOLD,24);<br> Thread number1;//The first number to display<br> //Thread number2;//the second number to display<br><br> int count;<br> String displayStr;<br><br><br> public static void main(String[] args) <br> {<br> new ThreadTest();<br> <br> }<br><br> public ThreadTest()<br> {<br> super("Thread Testing"<br> setSize(300,300);<br> <br> addWindowListener(new MyWindowListener());<br> <br> count = 0;<br><br> number1 = new Thread(this);<br> <br> number1.start();<br> <br> setVisible(true);<br> <br> }<br><br><br> public void run()<br><br> {<br><br> while (count < 1000)<br><br> {<br><br> ++count;<br><br> displayStr = String.valueOf(count);<br> validate();<br> repaint();<br> <br><br> try<br><br> {<br> number1.sleep(100);<br> }<br><br> catch (InterruptedException e)<br><br> {<br><br> }<br><br> }<br><br> }<br><br><br><br> public void paint(Graphics g)<br><br> { <br> g.setFont(theFont); <br> g.drawString(displayStr, 150, 150);<br> <br> }<br><br><br><br><br><br> public class MyWindowListener extends WindowAdapter<br> {<br> public void windowClosing(WindowEvent e)<br> {System.exit(0);}<br><br> }<br><br>}