Javaexamples-gui-transparent

提供:Dev Guides
移動先:案内検索

Javaの例-透明カーソルを作成する

問題の説明

透明カーソルを作成する方法は?

溶液

次の例は、「invisiblecursor」を引数としてcreateCustomCursor()メソッドを使用して、透明カーソルを作成する方法を示しています。

import java.awt.*;
import java.awt.image.MemoryImageSource;

public class Main {
   public static void main(String[] argv) throws Exception {
      int[] pixels = new int[16 * 16];
      Image image = Toolkit.getDefaultToolkit().createImage(
         new MemoryImageSource(16, 16, pixels, 0, 16));
      Cursor transparentCursor = Toolkit.getDefaultToolkit().createCustomCursor(
         image, new Point(0, 0), "invisibleCursor");
      System.out.println("Transparent Cursor created.");
   }
}

結果

上記のコードサンプルは、次の結果を生成します。

Transparent Cursor created.

以下は、透明カーソルを作成する例です。

import java.awt.*;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;

public class Panel {
   public static void main(String[] argv) throws Exception {
      JFrame frame = new JFrame();
      frame.setCursor(frame.getToolkit().createCustomCursor(
         new BufferedImage(3, 3, BufferedImage.TYPE_INT_ARGB), new Point(0, 0),"null"));
   }
}