⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jmicon.java

📁 梦界家园程序开发基底框架
💻 JAVA
字号:
package jm.framework.gui.module;

import java.awt.Image;
import java.net.URL;

import javax.swing.ImageIcon;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;
import java.net.URLClassLoader;
import javax.imageio.ImageIO;

public class JMIcon extends ImageIcon {
	private static final long serialVersionUID = 6223129139018777076L;

	private byte[] data = null;

	public JMIcon(String filename, String description) {
		super(filename, description);
	}

	/**
	 * Creates an ImageIcon from the specified file. The image will be preloaded
	 * by using MediaTracker to monitor the loading state of the image. The
	 * specified String can be a file name or a file path. When specifying a
	 * path, use the Internet-standard forward-slash ("/") as a separator. (The
	 * string is converted to an URL, so the forward-slash works on all
	 * systems.) For example, specify:
	 *
	 * <pre>
	 * new ImageIcon(&quot;images/myImage.gif&quot;)
	 * </pre>
	 *
	 * The description is initialized to the <code>filename</code> string.
	 *
	 * @param filename
	 *            a String specifying a filename or path
	 * @see #getDescription
	 */
	public JMIcon(String filename) {
		super(filename, filename);
	}

	/**
	 * Creates an ImageIcon from the specified URL. The image will be preloaded
	 * by using MediaTracker to monitor the loaded state of the image.
	 *
	 * @param location
	 *            the URL for the image
	 * @param description
	 *            a brief textual description of the image
	 * @see #ImageIcon(String)
	 */
	public JMIcon(URL location, String description) {
		super(location, description);
	}

	/**
	 * Creates an ImageIcon from the specified URL. The image will be preloaded
	 * by using MediaTracker to monitor the loaded state of the image. The
	 * icon's description is initialized to be a string representation of the
	 * URL.
	 *
	 * @param location
	 *            the URL for the image
	 * @see #getDescription
	 */
	public JMIcon(URL location) {
		super(location, location.toExternalForm());
	}

	/**
	 * Creates an ImageIcon from the image.
	 *
	 * @param image
	 *            the image
	 * @param description
	 *            a brief textual description of the image
	 */
	public JMIcon(Image image, String description) {
		super(image, description);
	}

	/**
	 * Creates an ImageIcon from an image object. If the image has a "comment"
	 * property that is a string, then the string is used as the description of
	 * this icon.
	 *
	 * @param image
	 *            the image
	 * @see #getDescription
	 * @see java.awt.Image#getProperty
	 */
	public JMIcon(Image image) {
		super(image);
	}

	/**
	 * Creates an ImageIcon from an array of bytes which were read from an image
	 * file containing a supported image format, such as GIF, JPEG, or (as of
	 * 1.3) PNG. Normally this array is created by reading an image using
	 * Class.getResourceAsStream(), but the byte array may also be statically
	 * stored in a class.
	 *
	 * @param imageData
	 *            an array of pixels in an image format supported by the AWT
	 *            Toolkit, such as GIF, JPEG, or (as of 1.3) PNG
	 * @param description
	 *            a brief textual description of the image
	 * @see java.awt.Toolkit#createImage
	 */
	public JMIcon(byte[] imageData, String description) {
		super(imageData, description);
		data = imageData;
	}

	/**
	 * Creates an ImageIcon from an array of bytes which were read from an image
	 * file containing a supported image format, such as GIF, JPEG, or (as of
	 * 1.3) PNG. Normally this array is created by reading an image using
	 * Class.getResourceAsStream(), but the byte array may also be statically
	 * stored in a class. If the resulting image has a "comment" property that
	 * is a string, then the string is used as the description of this icon.
	 *
	 * @param imageData
	 *            an array of pixels in an image format supported by the AWT
	 *            Toolkit, such as GIF, JPEG, or (as of 1.3) PNG
	 * @see java.awt.Toolkit#createImage
	 * @see #getDescription
	 * @see java.awt.Image#getProperty
	 */
	public JMIcon(byte[] imageData) {
		super(imageData);
		data = imageData;
	}

	public synchronized byte[] getByteArrays() {
		return data;
	}

	/**
	 * Creates an uninitialized image icon.
	 */
	public JMIcon() {
		super();
	}

    public static BufferedImage getBufferedImage (JFrame jfrm, String fileName) {
        BufferedImage bid = null;
        try {
            URLClassLoader urlLoader = (URLClassLoader) jfrm.getClass().getClassLoader();
            bid = ImageIO.read(urlLoader.getResourceAsStream(fileName));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return bid;
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -