TITLE:Cursorのアニメーション
#navi(../)
*Cursorのアニメーション [#j7158da4]
>編集者:[[Terai Atsuhiro>terai]]~
作成日:2006-05-01~
更新日:&lastmod;

#contents

**概要 [#h001fd76]
マウスカーソルをアニメーションさせます。

#screenshot

**サンプルコード [#h16203df]
 list[0] = tk.createCustomCursor(tk.createImage(url00), p, "00");
 list[1] = tk.createCustomCursor(tk.createImage(url01), p, "01");
 list[2] = tk.createCustomCursor(tk.createImage(url02), p, "02");
 setCursor(list[0]);
 animator = new javax.swing.Timer(100, new ActionListener() {
   private int count = 0;
   public void actionPerformed(ActionEvent e) {
     setCursor(list[count]);
     count = (count<list.length-1)?count+1:0;
   }
 });
 JButton button = new JButton(new AbstractAction("Start Animation") {
   public void actionPerformed(ActionEvent e) {
     JButton button = (JButton)e.getSource();
     if(animator.isRunning()) {
       button.setText("スタート");
       animator.stop();
     }else{
       button.setText("ストップ");
       animator.start();
     }
   }
 });

-&jnlp;
-&jar;
-&zip;

**解説 [#b3798cf8]
上記のサンプルでは、ボタンをクリックすると、カーソルがアニメーションするようになっています。透過pngファイルをコマにして、Timerで順番にこれを切り替えています。

Cursorに用いるpngファイルは、フルカラーではなく256色にしておかないと、うまく透過できないようです。

元にしたaniファイルは、[[VIPポインタ - Google 検索>http://www.google.com/search?client=opera&rls=en&q=VIP%E3%83%9D%E3%82%A4%E3%83%B3%E3%82%BF&sourceid=opera&ie=utf-8&oe=utf-8]]を利用しています。

**参考リンク [#bf958cfb]
-[[Cursorオブジェクトの生成>Swing/CustomCursor]]
-[[oreilly.co.jp -- Online Catalog: Java Swing Hacks>http://www.oreilly.co.jp/books/4873112788/download.html]]

**コメント [#q9ef944e]
#comment