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

📄 imagesetloader.java

📁 一个很不错的j2me的rpg游戏的源码
💻 JAVA
字号:
package mobileRPG.client;

import javax.microedition.lcdui.*;

public class ImageSetLoader extends Canvas {
	
    // Used in paint()
	private int backgroundcolor = 0xFFFFFF;
    private int foregroundcolor = 0x000000;   
    private int xSize, ySize;
    private String message, name;
    private int progress;
    private Main main;
    static public Image defaultImage;

    public ImageSetLoader(Main main) {
		xSize = getWidth();
		ySize = getHeight();
		this.main = main;
		
		try {
			if (defaultImage == null) {
				defaultImage = Image.createImage("/res/images/Blank.png");
			}
		} catch (Exception ee) {}
    }
    
    public ImageSet loadImages(ConfigFile cf, String name, boolean showLoadingScreen) {
    	int imageCount;
        String[] buffer = null;
        ImageSet imageSet;
        
        this.name = name;
        
        if (showLoadingScreen) {
        	main.showLoadingScreen();
        }
        
        message = "Loading... 0%";
		progress = 0;

		imageCount = cf.readIntLine();
		imageSet = new ImageSet(imageCount);
				
		imageCount = 0;
		buffer = cf.readArrayLine('|');
		while (!cf.isClosed() && buffer.length > 1) {
			
			// Read the Image ID
			imageSet.imageID[imageCount] = Integer.parseInt(buffer[0]);
			
			// Read the image data
			try {
				imageSet.image[imageCount] = Image.createImage(buffer[1]);
			} catch (Exception e) {
				System.err.println("Error Loading ImageSet: " + e.toString());
				System.err.println("   " + buffer[1]);
				
				try {
					imageSet.image[imageCount] = Image.createImage("/res/images/Blank.png");
				} catch (Exception ee) {}
				
				//message = e.toString();
				//repaint();
			}
			
			imageCount++;
			progress = (imageCount * 100) / imageSet.imageID.length;
			message = "Loading... " + progress + "%";
        	repaint();
 			Thread.yield();
 			
 			buffer = cf.readArrayLine('|');
		}
        message = "Loading... Complete";
        progress = 100;
        repaint();
        
        if (showLoadingScreen) {
        	main.hideLoadingScreen();
        }
        
        return imageSet;
    }
	
    protected void paint(Graphics g) {
    	g.setColor(backgroundcolor);
        g.fillRect(0, 0, xSize, ySize);
        
        g.setColor(foregroundcolor);
        g.drawRect(10, 10, xSize - 20, 10);
        g.fillRect(10, 10, ((xSize - 20) * progress) / 100, 10);
        
        if (message != null) {
        	g.drawString(message, 10, 30, Graphics.TOP|Graphics.LEFT);
        }
        if (name != null) {
        	g.drawString(name, 10, 42, Graphics.TOP|Graphics.LEFT);
        }
        g.drawString("Mobile RPG Engine v0.3", 10, getHeight()-20, Graphics.TOP|Graphics.LEFT);
    }

    protected void keyPressed(int keyCode) {}
    
}

⌨️ 快捷键说明

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