⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 resource.java

📁 这是我写的一个j2me的名为《黄金甲》的一个RPG游戏
💻 JAVA
字号:


package Engine;
import java.io.InputStream;
import java.io.DataInputStream;
import javax.microedition.lcdui.Image;

/*
 *
 * @author 裴明巍
 */
public class Resource
{
    private String ResName; // resource file name
    private int Total; // file total
    private String FileName[]; // file name
    private int FileLenght[]; // file lenght
    private byte FileData[][]; // file data
    
    /** Creates a new instance of Resource */
    public Resource(String Name)
    {
        DataInputStream dis;
        String Temp = null;
        int Count;
        int Length;
        
        ResName = Name;
        try
        {
            dis = new DataInputStream(this.getClass().getResourceAsStream(ResName));
            // read data
            Total = dis.readInt(); // read file total
            // create array
            FileName = new String[Total];
            FileLenght = new int[Total];
            FileData = new byte[Total][];
             // read file content
            for(Count = 0; Count < Total; Count++)
            {
                FileName[Count] = dis.readUTF(); // name
                FileLenght[Count] = dis.readInt(); // size
                FileData[Count] = new byte[FileLenght[Count]]; //create file data arrary
                dis.read(FileData[Count], 0, FileData[Count].length);// data
            }
            // read end
            dis.close();
        }
        catch(Exception e)
        {
            System.out.println(e.toString());
        }
    }

    /*
     * function:Creates an resource packet from the named file.
     * name:the name of the resource file.
     * Returns:the created resource.
     */
    public static Resource createResource(String name)
    {
        return new Resource(name);
    }

    /*
     * function:Creates an immutable image.
     * name:the name of the image.
     * Returns:the created image.
     */
    public Image createImage(String name)
    {
        Image img = null;
        int Index;
        
        for(Index = 0; Index < Total; Index++)
        {
            // get file index
            if(FileName[Index].compareTo(name) == 0)
            {
                img = Image.createImage(FileData[Index], 0, FileData[Index].length);
                break;
            }
        }       
        return img;
    }
    
}

⌨️ 快捷键说明

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