今天没什么事情,写了一个简单的小说阅读器,由于我的手机3230不支持jsr75,所以就把小说内容与代码放到了一起,如果大家想写一个支持读取本地文件的小说阅读器,那也很简单,用FileConnection读取即可。
这是全部代码,有什么问题可以一起探讨
第一,MIDlet类
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class MainMidlet extends MIDlet {
public MainMidlet() {
Display.getDisplay(this).setCurrent(new InitSrc());
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void startApp() throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
}
第二,常量类
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.jinguo.ui;
/**
*
* @author Administrator
*/
public class Const {
public static final int KEY_UP=-1;
public static final int KEY_DOWN=-2;
public static final int KEY_LEFT=-3;
public static final int KEY_RIGHT=-4;
}
第三,Canvas类
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Vector;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import org.jinguo.ui.Const;
public class InitSrc extends Canvas implements Runnable {
private Font font;
private String[] helpArray = null;
private int rendNum; // 屏幕显示文本的行数
private int strMainInd