Advertisement
Guest User

Untitled

a guest
Apr 12th, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1. public Image loadImage(String name)
  2. {
  3.     Image result = cache.get(name);
  4.    
  5.     if (result == null)
  6.     {
  7.         try
  8.         {
  9.             result = ImageIO.read(new File("res/images/" + name));
  10.         }
  11.         catch (IOException e1)
  12.         {
  13.             try
  14.             {
  15.                 InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream("res/images/" + name);
  16.                 if (is == null)
  17.                 {
  18.                     throw new IOException();
  19.                 }
  20.                 result = ImageIO.read(is);
  21.             }
  22.             catch (IOException e2)
  23.             {
  24.                 System.err.println("Failed to load image: " + name);
  25.             }
  26.         }
  27.        
  28.         if (result == null)
  29.         {
  30.             result = imageNotFound;
  31.         }
  32.     }
  33.    
  34.     cache.put(name, result);
  35.    
  36.     return result;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement