Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.awt.*;

import java.awt.image.*;

public class Main {
    public static Cursor buildCursorByTrimming(Image image, String name, Cursor defaultCursor) {
        return buildCursorByTrimming(image, 0, 0, name, defaultCursor);
    }

    public static Cursor buildCursorByTrimming(Image image, int x, int y, String name, Cursor defaultCursor) {
        return buildCursorByTrimming(Toolkit.getDefaultToolkit(), image, x, y, name, defaultCursor);
    }

    public static Cursor buildCursorByTrimming(Toolkit toolkit, Image image, int x, int y, String name,
            Cursor defaultCursor) {
        Dimension d = toolkit.getBestCursorSize(image.getWidth(null), image.getHeight(null));
        if (d == null || d.getWidth() <= 0 || d.getHeight() <= 0)
            return defaultCursor;
        BufferedImage out = new BufferedImage((int) d.getWidth(), (int) d.getHeight(), BufferedImage.TYPE_INT_ARGB);
        out.getGraphics().drawImage(image, 0, 0, null);
        return toolkit.createCustomCursor(out, new Point(x, y), name);
    }
}