List of usage examples for java.lang Class getResource
@CallerSensitive
public URL getResource(String name)
From source file:Main.java
public static void main(String args[]) { Class theClass = Main.class; java.net.URL u = theClass.getResource(""); System.out.println("This class (FromWhere) is located at : " + u); }
From source file:SIFT_Volume_Stitching.java
public static void main(String[] args) { // set the plugins.dir property to make the plugin appear in the Plugins menu Class<?> clazz = SIFT_Volume_Stitching.class; String url = clazz.getResource("/" + clazz.getName().replace('.', '/') + ".class").toString(); String pluginsDir = url.substring("file:".length(), url.length() - clazz.getName().length() - ".class".length()); System.setProperty("plugins.dir", pluginsDir); // start ImageJ new ImageJ(); // open the Clown sample ImagePlus image1 = IJ.openImage("https://www.creatis.insa-lyon.fr/~frindel/BackStack115.tif"); ImagePlus image2 = IJ.openImage("https://www.creatis.insa-lyon.fr/~frindel/FrontStack.tif"); image1.show();// w ww . ja v a2 s . co m image2.show(); // run the plugin IJ.runPlugIn(clazz.getName(), ""); }
From source file:Main.java
public static File getClassFile(Class clazz) { URL path = clazz.getResource(clazz.getName().substring(clazz.getName().lastIndexOf("") + 1) + ".classs"); if (path == null) { String name = clazz.getName().replaceAll("[.]", "/"); path = clazz.getResource("/" + name + ".class"); }//from www . j a v a 2 s. c o m return new File(path.getFile()); }
From source file:Main.java
public static final ImageIcon loadIcon(Class pRootClass, String strPath) { URL imgURL = pRootClass.getResource(strPath); if (imgURL != null) return new ImageIcon(imgURL); else//ww w . j av a2 s . c o m return null; }
From source file:Main.java
private static URL getResourceURL(Class owner, String item) { return owner.getResource("/org/isqlviewer/resource/".concat(item)); }
From source file:Main.java
public static Image genImageResource(Class<?> cls, String icon) { Image img = new ImageIcon(cls.getResource(icon)).getImage(); return img;//w w w.j av a 2 s . c om }
From source file:Main.java
/** * Returns an ImageIcon, or throws a RuntimeException if the path was * invalid./* w ww . j a v a 2s.c om*/ * @param clazz The class to "baseline" the path off of. * @param path The path from the location of the "baseline" class (clazz). * @return An ImageIcon object. */ public static ImageIcon createImageIcon(Class clazz, String path) { URL imageUrl = clazz.getResource(path); if (imageUrl != null) { return new ImageIcon(imageUrl); } throw new RuntimeException("Couldn't find file: " + path); }
From source file:Main.java
/** * return image icon from resource location ( ie Classpath ) * File could be placed in the classpath or in a jar file * @param aFilename file name of the image file * @param aRetrieverClass class request for the image * @return image icon//from w ww .j av a2 s . co m */ public final static ImageIcon GetImageFromResource(String aFilename, Class aRetrieverClass) { URL url = null; url = aRetrieverClass.getResource(aFilename); if (url == null) return null; else return new ImageIcon(url); }
From source file:com.boozallen.cognition.test.utils.TestResourceUtils.java
public static URL getResource(Class<?> testClass, String resource) { return testClass.getResource(getResourcePath(testClass, resource)); }
From source file:Main.java
/** * Loads a icon from either the file system or from a jar. * * @param clas A class used to resolve the icon's relative path name * @param iconPath the path relative to the clas in which to find the icon. * @return an image icon for the icon, or null if not found * * <pre>//from w w w. j ava 2 s . c o m * for a directory structure like * edu/ * mypackage/ * MyClass.class * images/ * myicon.gif * * call loadImageIcon(MyClass.class, "images/myicon.gif"); * * </pre> */ public static ImageIcon loadImageIcon(Class clas, String iconPath) { ImageIcon icon = null; URL url = clas.getResource(iconPath); if (url != null) { icon = new ImageIcon(url); } return icon; }