import javax.swing.ImageIcon;
import java.awt.Image;
import java.awt.Toolkit;
import java.io.File;
import java.applet.Applet;
import java.applet.AudioClip;
/**
*
* <p>Title: 获取资源</p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2008</p>
* <p>Company: </p>
* @author landix
* @version 1.0
*/
public class ResourceManager {
//系统图片路径
private static String IMAGE_RESOURCE_PATH = "com/landix/oamq/client/images/";
//系统音频路径
private static String SOUND_RESOURCE_PATH = "com/landix/oamq/client/sound/";
//系统文件路径
private static String FILE_RESOURCE_PATH = "";
private ResourceManager() {
}
public static ImageIcon getIcon(String imageName) {
if (imageName == null) return(null);
ImageIcon icon = null;
try {
//通过类加载器加载图片资源,作为图标对象的参数
icon = new ImageIcon(ResourceManager.class.getClassLoader()
.getResource(IMAGE_RESOURCE_PATH + imageName));
} catch (Exception ex) {
System.out.println ("### Exception in getIcon() : \r\n" + IMAGE_RESOURCE_PATH + imageName + " " + ex.toString());
}
return icon;
}
public static Image getImage(String imageName) {
if (imageName == null) return(null);
Image image = null;
try {
//通过类加载器加载图片资源,作为图标对象的参数
image = Toolkit.getDefaultToolkit().getImage(ResourceManager.class.getClassLoader()
.getResource(IMAGE_RESOURCE_PATH + imageName));
} catch (Exception ex) {
System.out.println ("### Exception in getIcon() : \r\n" + IMAGE_RESOURCE_PATH + imageName + " " + ex.toString());
}
return image;
}
public static AudioClip getSound(String soundName) {
if (soundName == null) return(null);
AudioClip wowo = null ;
try {
//通过类加载器加载声音资源,作为声音对象的参数
wowo = Applet.newAudioClip(ResourceManager.class.getClassLoader()
.getResource(SOUND_RESOURCE_PATH + soundName));
} catch ( Exception ex ) {
System.out.println ("### Exception in getIcon() : \r\n" + SOUND_RESOURCE_PATH + soundName + " " + ex.toString());
}
return wowo;
}
public static File getFile(String fileName) {
if (fileName == null) return(null);
File file = null;
try {
//通过类加载器加载文件资源,作为文件对象的参数
file = new File(ResourceManager.class.getClassLoader()
.getResource(FILE_RESOURCE_PATH + fileName).toString());
} catch (Exception ex) {
System.out.println ("### Exception in getIcon() : \r\n" + FILE_RESOURCE_PATH + fileName + " " + ex.toString());
}
return file;
}
}
java中调用图片音频等文件的相对路径问题
最新推荐文章于 2022-12-02 18:42:06 发布