Here you can find the source of loadImage(String imageName)
Parameter | Description |
---|---|
imageName | path to image |
Parameter | Description |
---|---|
IllegalArgumentException | when image can't be found in classpath |
public static Image loadImage(String imageName)
//package com.java2s; //License from project: LGPL import java.awt.Image; import java.awt.Toolkit; import java.net.URL; public class Main { private static final String IMAGE_PATH = "images/"; /**//from w w w . ja v a2 s . com * Loads an image from the given path. * * @param imageName path to image * @return loaded image * @throws IllegalArgumentException when image can't be found in classpath */ public static Image loadImage(String imageName) { URL imageUrl = Thread.currentThread().getContextClassLoader().getResource(IMAGE_PATH + imageName); if (imageUrl == null) { throw new IllegalArgumentException("'" + imageName + "' could not be found in classpath"); } return Toolkit.getDefaultToolkit().getImage(imageUrl); } }