MovePattern.java



import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;

/** 繰り返して図形を描く MovePattern クラスの定義 */

public class MovePattern extends Applet implements Runnable {

    /** タイマーのスレッド */

       public Thread timer = null;

    /** 図形の位置と座標 */

       protected int x, y, w, h;

    /** 図形のクリアを実行するかどうか */

       protected boolean clearFlag = true;

    /** アプレットの表示(初期状態)を行うメソッド */
 
       public void paint( Graphics g ) {
 
             g.setColor( Color.black );
             g.fill3DRect( 0, 0, size().width-2, size().height-2, false );
             clearFlag = false;
       }
 
    /** アプレットの表示の更新を行うメソッド */
 
       public void update( Graphics g ) {
 
             if( clearFlag == true ) {

                  paint( g );
             }
             else {
                  g.setColor( Color.magenta );
                  g.drawArc( x, y, w, h, 0, 360 );
             }
       }

    /** アプレットが画面に現れた時に呼び出される。*/

       public void start() {

             if( timer == null ) {
                   timer = new Thread(this);  // スレッド生成
                   timer.start();             // スレッド起動
             }
       }

    /** アプレットが画面から消えた時に呼び出される。*/

       public void stop() {

             if( timer != null ) {
                   timer.stop();           // スレッド停止
                   timer = null;           // スレッド消去
             }
       }

    /** スレッドとして行われる処理 */

       public void run() {

              while( timer.isAlive() ) {

                    y=150; w=200; h=10;
                    for( x=0; x<100; x+=4 ) {
                        repaint();
                        try { Thread.sleep( 200 ); }    // 0.2秒停止
                        catch(InterruptedException e){ }
                        y-=4; w+=8; h+=8;
                    }
                    clearFlag = true;
                    repaint();
              }
       }
}