home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-03-20 | 931 b | 52 lines |
- import java.awt.*;
- import java.applet.*;
-
- public class ThreadApplet extends Applet
- implements Runnable
- {
- Thread thread;
- int count;
- String displayStr;
- Font font;
-
- public void start()
- {
- font = new Font("TimesRoman", Font.PLAIN, 72);
- setFont(font);
-
- count = 0;
- displayStr = "";
-
- thread = new Thread(this);
- thread.start();
- }
-
- public void stop()
- {
- thread.stop();
- }
-
- public void run()
- {
- while (count < 1000)
- {
- ++count;
- displayStr = String.valueOf(count);
- repaint();
-
- try
- {
- thread.sleep(100);
- }
- catch (InterruptedException e)
- {
- }
- }
- }
-
- public void paint(Graphics g)
- {
- g.drawString(displayStr, 50, 130);
- }
- }
-