• title: Cursorのアニメーション tags: [Cursor, Animation] author: aterai pubdate: 2006-05-01T12:35:56+09:00 description: マウスカーソルをアニメーションさせます。

概要

マウスカーソルをアニメーションさせます。

サンプルコード

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;
  @Override public void actionPerformed(ActionEvent e) {
    setCursor(list[count]);
    count = (count + 1+ list.length) % list.length;
  }
});
JButton button = new JButton(new AbstractAction("スタート") {
  @Override public void actionPerformed(ActionEvent e) {
    JButton button = (JButton)e.getSource();
    if(animator.isRunning()) {
      button.setText("スタート");
      animator.stop();
    }else{
      button.setText("ストップ");
      animator.start();
    }
  }
});
View in GitHub: Java, Kotlin

解説

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

各コマは、ぶーん(通常の選択.ani、VIPポインタ)から、ANIめーかーを使って生成しています。

参考リンク

コメント