Here you can find the source of createCursor(Image image, Point hotspot, String name)
Parameter | Description |
---|---|
image | the image for the cursor |
hotspot | the cursor's hotspot |
name | the name of the cursor |
public static Cursor createCursor(Image image, Point hotspot, String name)
//package com.java2s; /*//from ww w . j av a2s . c o m * Copyright appNativa Inc. All Rights Reserved. * * This file is part of the Real-time Application Rendering Engine (RARE). * * RARE is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ import java.awt.Cursor; import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.Image; import java.awt.Point; import java.awt.Toolkit; import java.awt.image.BufferedImage; import javax.swing.ImageIcon; public class Main { /** * Creates a cursor from an ImageIcon * * @param icon the icon for the cursor * @param hotspot the cursor's hotspot * * @return the newly created cursor */ public static Cursor createCursor(ImageIcon icon, Point hotspot) { if (icon == null) { return null; } return createCursor(icon.getImage(), hotspot, icon.getDescription()); } /** * Creates a cursor from an image * * @param image the image for the cursor * @param hotspot the cursor's hotspot * @param name the name of the cursor * * @return the newly created cursor */ public static Cursor createCursor(Image image, Point hotspot, String name) { int w = image.getWidth(null); int h = image.getHeight(null); Dimension size = Toolkit.getDefaultToolkit().getBestCursorSize(w, h); if ((size.width != w) || (size.height != h)) { BufferedImage b = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB); Graphics2D g = b.createGraphics(); g.drawImage(image, 0, 0, null); image = b; g.dispose(); } if (hotspot == null) { hotspot = new Point(0, 0); } return Toolkit.getDefaultToolkit().createCustomCursor(image, hotspot, name); } }