CursorSample.java



import java.awt.*;
import java.applet.Applet;

/** JDK1.1 に追加された Cursorを含むアプレット CursorSamples クラス */

public class CursorSample extends Applet implements Runnable{

   /** カーソルの宣言(全種類を確認するため配列) */ 

      public Cursor cursors[];

   /** カーソルの番号を表すカウンター( 0 - 13 ) */ 

      protected int count=0;

   /** カーソルを再設定するためのスレッド */ 

      public Thread timer;

   /** 初期設定のメソッド */

      public void init() {

          cursors = new Cursor[14];
          cursors[0] = new Cursor( Cursor.CROSSHAIR_CURSOR );
          cursors[1] = new Cursor( Cursor.DEFAULT_CURSOR );
          cursors[2] = new Cursor( Cursor.E_RESIZE_CURSOR );
          cursors[3] = new Cursor( Cursor.HAND_CURSOR );
          cursors[4] = new Cursor( Cursor.MOVE_CURSOR );
          cursors[5] = new Cursor( Cursor.N_RESIZE_CURSOR );
          cursors[6] = new Cursor( Cursor.NE_RESIZE_CURSOR );
          cursors[7] = new Cursor( Cursor.NW_RESIZE_CURSOR );
          cursors[8] = new Cursor( Cursor.S_RESIZE_CURSOR );
          cursors[9] = new Cursor( Cursor.SE_RESIZE_CURSOR );
          cursors[10] = new Cursor( Cursor.SW_RESIZE_CURSOR );
          cursors[11] = new Cursor( Cursor.TEXT_CURSOR );
          cursors[12] = new Cursor( Cursor.W_RESIZE_CURSOR );
          cursors[13] = new Cursor( Cursor.WAIT_CURSOR );
      }

   /** スタート時の処理 */

      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() ) {

              setCursor( cursors[ count ] );  // カーソルの再設定
              try { Thread.sleep( 1000 ); }
              catch( InterruptedException e ) { }
              count++;
              if( count < 0 || 14 <= count )  count=0;
          }
      }
}