imageloader.java

来自「WebHangman a game can be play on the web」· Java 代码 · 共 35 行

JAVA
35
字号
package com.aztsoft.games.util;

import java.awt.*;
import java.applet.Applet;
import java.io.IOException;

/**
 * Utilitty class to load images
 */
public class ImageLoader {
    static boolean runAsApplication = false;

    /**
     * Utility method to return an image by name
     *
     */
    public static Image loadImage(String relName, Applet thisApplet) throws IOException {
        if (runAsApplication) {
            MediaTracker tracker = new MediaTracker(thisApplet);
            Image imtexture = Toolkit.getDefaultToolkit().getImage(relName);
            tracker.addImage(imtexture, 0);
            try {
                tracker.waitForID(0);
                int width = imtexture.getWidth(thisApplet);
                int height = imtexture.getHeight(thisApplet);
            }
            catch (InterruptedException e) {
                GameLogger.log("Interrupted Exception on Image-Texture Loading", e);
            }
            return imtexture;
        } else {
            return (thisApplet.getImage(thisApplet.getCodeBase(), relName));
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?