home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-04-15 | 2.3 KB | 98 lines |
- /**
- *
- * ImageManager.java
- * @author Mark G. Tacchi (mtacchi@next.com)
- * @version 0.8
- * Mar 19/1996
- *
- * ImageManager is used to force-load images at once to avoid taking
- * the hit during gameplay and distrupting game flow. Images to be cached
- * are listed in a cache file located in the <codebase>/images directory. The
- * default cache file is images/.cache.
- *
- */
-
- package com.next.gt;
-
- //import java.net.*;
- import java.io.*;
- import java.awt.*;
- import java.awt.image.*;
-
- public class ImageManager extends java.lang.Object{
- Gamelication owner;
-
- /**
- Cache those images which are listed in images/.cache.
- */
- public ImageManager(Gamelication theOwner) {
- this(theOwner, ".cache");
- } /*ImageManager()*/
-
-
-
- /**
- Cache those images which are listed in the specified cache file.
- This cache file should exist under the images directory.
- */
- public ImageManager(Gamelication theOwner, String cacheFile) {
- //URL myURL= null;
- File myfile;
- FileReader myReader;
- BufferedReader data;
- String line;
- Image theImage;
- Image offScreenBuffer;
- MediaTracker tracker;
- int imageCount= 0;
-
- owner= theOwner;
-
- //
- // create the offscreen buffer
- //
- offScreenBuffer= owner.createImage ( 1, 1 );
-
- //
- // create URL that points to cache file. the cache file lists all images
- // that are to be preloaded.
- //
- myfile= new File ( owner.getCodeBase().toString()+"/images/" + cacheFile );
-
- //
- // cycle through all images
- //
- tracker= new java.awt.MediaTracker(owner);
- try {
- myReader = new FileReader( myfile );
- data= new BufferedReader( myReader );
- while ((line= data.readLine())!=null) {
- imageCount++;
- theImage = owner.getImage(owner.getCodeBase(), "images/"+line+".gif");
-
- tracker.addImage(theImage, imageCount);
- owner.showStatus ("GT: Caching image: " + line + "." );
-
- //
- // wait for images to be cached
- //
- try{
- tracker.waitForID(imageCount);
- }
- catch (InterruptedException e) {
- System.out.println("GT: ImageManager ridiculous image; " + e.getMessage());
- }
- offScreenBuffer = owner.createImage ( 1, 1 );
- offScreenBuffer.getGraphics().drawImage (theImage, 0, 0, owner);
- } /*endWhile*/
- }
- catch(IOException e ){
- System.out.println("GOOF: ImageManager cannot getImage; " + e.getMessage());
- }
-
- } /*ImageManager(,)*/
-
-
- } /*ImageManager*/
-
-