Java中的鼠标光标

时间:2013-12-31 12:57:56

标签: java swing cursor jlist acm-java-libraries

你能告诉我,为什么它不起作用。当我运行它时,鼠标隐藏。但我想改变鼠标光标的图标。

import java.awt.Cursor;
import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;

import javax.swing.JList;

import acm.program.GraphicsProgram;

public class test1 extends GraphicsProgram {

    public Cursor stoneCursor;

    public void run() {
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Image image = toolkit.getImage("cursor.gif");
        Point hotspot = new Point(0, 0);
        stoneCursor = toolkit.createCustomCursor(image, hotspot, "Stone");
        getContentPane().setCursor(stoneCursor);
    }

    @Override
    public void mouseDragged(MouseEvent e) {
    }
}

1 个答案:

答案 0 :(得分:0)

这是一个例子试试这个..

标准光标图像:

setCursor (Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

用户定义的图片:

Toolkit toolkit = Toolkit.getDefaultToolkit();
  Image image = toolkit.getImage("icons/handwriting.gif");
  Cursor c = toolkit.createCustomCursor(image , new Point(mainPane.getX(),
     mainPane.getY()), "img");
  mainPane.setCursor (c);