基于MIDP实现ResourceBundle类[2]

[入库:2006年2月23日] [更新:2007年3月24日]

本文简介:

import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.TextBox;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;


public class IndexMIDlet extends MIDlet
{
    private ResourceBundle indexBundle;
    private Display display;
    private TextBox box;
    
    
    protected void startApp() throws MIDletStateChangeException
    {
        display = Display.getDisplay(this);
        try
        {
            indexBundle = new ResourceBundle("/index.properties",15);
        }
        catch(IOException e)
        {
            e.printStackTrace();
        }
        box = new TextBox("IndexBundle",null,256,TextField.ANY);
        box.setString(indexBundle.getString(2));
        display.setCurrent(box);
       
    }

   
    protected void pauseApp()
    {
    }

  
    protected void destroyApp(boolean arg0) throws MIDletStateChangeException
    {
    }

}

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Vector;


public class ResourceBundle
{
    private Vector indexVector;
    private String fileName;
  
    private ResourceBundle()
    {
    }

    public ResourceBundle(String fileName, int size) throws IOException
    {
        this.fileName = fileName;
        indexVector = new Vector(size);
        init();
    }

    private InputStream getInputStreamFromFile()
    {
        return new ResourceBundle().getClass().getResourceAsStream(
                fileName);
    }

    private void init() throws IOException
    {
        readToVector();
    }

    public String getString(int indexID)
    {
        if (indexID < 0 || indexID > indexVector.size())
        {
            return null;
        } else
        {
            return (String) indexVector.elementAt(indexID);
        }
    }

本文关键:基于MIDP实现ResourceBundle类
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top