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

📄 iconresources.java

📁 Java mulitplayer strategy game. Adaptation of KDE Galaxy Conquest. (rules are changed - but still th
💻 JAVA
字号:
/*
 * IconResources.java
 *
 * Created on 13 pa焏ziernik 2005, 20:58
 *
 * To change this template, choose Tools | Options and locate the template under
 * the Source Creation and Management node. Right-click the template and choose
 * Open. You can then make changes to the template in the Source Editor.
 */

package net.sf.jawp.gui.client;

import java.awt.image.BufferedImage;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import javax.imageio.ImageIO;

import net.sf.jawp.util.Log;

/**
 * Singleton helper class for reading icons.
 *
 * @author jarek
 */
public class IconResources
{
	private static final Log LOG = Log.getLog(IconResources.class); 
	
	private static final IconResources SINGLETON = new IconResources();
	
	
	private final HashMap<String, BufferedImage> images;
	
	/** Creates a new instance of IconResources */
	private IconResources()
	{
		this.images = new HashMap<String , BufferedImage>();
	}
	
	public static IconResources getInstance()
	{
		return IconResources.SINGLETON;
	}
	
	/**
	 * 
	 * @param name
	 * @return in case of problem returns null
	 */
	public final BufferedImage getImage(final String name)
	{
		BufferedImage result = images.get(name);
		if ( result == null )
		{
			try
			{
				result = read(name);
				this.images.put( name , result);
			}
			catch (final IOException e)
			{
				LOG.error(e, e);
			}
			
		}
		return result;
	}
	
	/**
	 * read icon with given name
	 */
	private BufferedImage read(final String name) throws IOException
	{
		final InputStream stream = getClass().getResourceAsStream("/icons/" + name + ".gif");
		if ( stream != null )
		{
			return ImageIO.read(stream);
		}
		else
		{
			throw new FileNotFoundException("resource:" + name);
		}
	}
	

}

⌨️ 快捷键说明

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