home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 14 / IOPROG_14.ISO / soft / sdkjava / sdkjava.exe / SDKJava.cab / Samples / AFC / LoanCalc / Src / LCImages.java < prev    next >
Encoding:
Java Source  |  1998-03-05  |  1.4 KB  |  53 lines

  1. //
  2. // (c) 1998 Microsoft Corporation.  All rights reserved.
  3. //
  4. import java.awt.Image;
  5. import java.awt.Toolkit;
  6. import java.awt.MediaTracker;
  7. import java.net.URL;
  8. import com.ms.ui.*;
  9.  
  10. //
  11. // This class assumes that an Images directory containing NUM_IMAGES 
  12. // images is contained in the application/applet directory.
  13. //
  14. public class LCImages implements LCConsts
  15. {
  16.     private static UIApplet applet = null;
  17.     private static MediaTracker tracker = null;
  18.     private static URL url = null;
  19.     private static Toolkit tk = null;
  20.     private static String filesep = System.getProperty("file.separator");
  21.  
  22.     private static Image img[] = new Image[NUM_IMAGES];
  23.  
  24.     public final static void init(UIApplet aplt, UIFrame frame)
  25.     {
  26.         if ( aplt != null ) {
  27.             applet = aplt;
  28.             tracker = new MediaTracker(applet.getApplet());
  29.             url = applet.getCodeBase();
  30.         }
  31.         else {
  32.             tracker = new MediaTracker(frame.getFrame());
  33.             tk = frame.getToolkit();
  34.         }
  35.     }
  36.  
  37.     public final static Image get(int idx)
  38.     {
  39.         Image image = img[idx];
  40.  
  41.         if ( image == null ) {
  42.             if ( applet != null )
  43.                 image = applet.getImage(url, "Images" + filesep + IMG_NAMES[idx]);
  44.             else
  45.                 image = tk.getImage("Images" + filesep + IMG_NAMES[idx]);
  46.             tracker.addImage(image, 0);
  47.             try { tracker.waitForAll(); } catch(InterruptedException e) { }
  48.             img[idx] = image;
  49.         }
  50.         return image;
  51.     }
  52. }
  53.