Java 怎么获取闭合指针

2019年8月19日22:33:50 评论 23

1.简介

Java 怎么获取闭合指针?——请看下文。

2.代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */

import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;

public class Main{
    protected static Cursor closedHandCursor;
    public static Cursor getClosedHandCursor() {
        if (closedHandCursor == null) {
            try {
                BufferedImage image = ImageIO
                        .read(CursorUtils.class
                                .getResourceAsStream("/m/resources/hand_closed.png"));
                Toolkit toolkit = Toolkit.getDefaultToolkit();
                Dimension dim = toolkit.getBestCursorSize(image.getWidth(),
                        image.getHeight());
                if (dim.width != image.getWidth()
                        || dim.height != image.getHeight()) {
                    BufferedImage newimage = new BufferedImage(dim.width,
                            dim.height, BufferedImage.TYPE_4BYTE_ABGR);
                    Graphics2D g2 = (Graphics2D) newimage.getGraphics();
                    g2.drawImage(image, 0, 0, new Color(255, 0, 0, 0), null);
                    image = newimage;
                }
                closedHandCursor = Toolkit.getDefaultToolkit()
                        .createCustomCursor(image, new Point(15, 15),
                                "ClosedHandCursor");
            } catch (IOException ignored) {
            }
        }
        return closedHandCursor;
    }
}

 

3.总结

示例代码演示了 Java 怎么获取闭合指针,具体步骤参见示例代码。

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: