imagestools.java

来自「eclipse下完成的一个扔鸡蛋的小游戏:)」· Java 代码 · 共 45 行

JAVA
45
字号
/*
 * Created on Apr 7, 2005
 *
 * TODO load the image to memory when this program is loaded, then program can
 * use image from memory directly
 */
package mqqqvpppm.util;

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

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;



/**
 * @author mqqqvpppm
 * 
 * TODO load the image to memory when this program is loaded, then program can
 * use image from memory directly
 */
public class ImagesTools {
	/** Returns an ImageIcon, or null if the path was invalid. */
	public static ImageIcon createImageIcon(java.net.URL imgURL) {		
		if (imgURL != null) {
			return new javax.swing.ImageIcon(imgURL);
		} else {
			System.err.println("Couldn't find file in: " + imgURL.getPath());
			return null;
		}
	}

	public static Image createImage(URL imgURL) {
		if(imgURL == null) return null;
		try {			
			Image ret = ImageIO.read(imgURL);
			return ret;
		} catch (Exception exception) {
			System.err.println("Couldn't find file in: " + imgURL.getPath());
			return null;
		}
	}

}

⌨️ 快捷键说明

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