home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-03-21 | 1.1 KB | 64 lines |
- import java.awt.*;
- import java.applet.*;
-
- public class ThreadApplet4 extends Applet
- implements Runnable
- {
- Thread thread;
- int count;
- String displayStr;
- Font font;
-
- public void init()
- {
- font = new Font("TimesRoman", Font.PLAIN, 72);
- setFont(font);
-
- count = 0;
- displayStr = "";
-
- thread = new Thread(this);
- }
-
- public void start()
- {
- if (thread.isAlive())
- thread.resume();
- else
- thread.start();
- }
-
- public void stop()
- {
- thread.suspend();
- }
-
- public void destroy()
- {
- 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);
- }
- }
-