Advertisement
StormWingDelta

ImageLoader

May 26th, 2012
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1. This is only the part of the class that loads the images
  2.  
  3.     private URL getURL(String filename) {
  4.         URL url = null;
  5.         try {
  6.             url = this.getClass().getResource(filename);
  7.             //url = new java.net.URL(applet.getCodeBase() + filename);
  8.         }
  9.         //catch (MalformedURLException e) { e.printStackTrace(); }
  10.         catch (Exception e) { }
  11.  
  12.         return url;
  13.     }
  14.  
  15.     public void load(String filename) {
  16.         Toolkit tk = Toolkit.getDefaultToolkit();
  17.         image = tk.getImage(getURL(filename));
  18.         while(getImage().getWidth(applet) <= 0){loaded = false;}
  19.         double x = applet.getSize().width/2  - width()/2;
  20.         double y = applet.getSize().height/2 - height()/2;
  21.         at = AffineTransform.getTranslateInstance(x, y);
  22.         loaded = true;
  23.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement