求助!! 急用
求高手将下列代码加上注释!import javax.microedition.rms.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.microedition.io.*;
import java.util.Enumeration;
import java.util.Date;
import java.util.Calendar;
import java.io.*;
public class IncomeDemo extends MIDlet implements CommandListener {
Display display = null;
//初始化菜单
List menu = null;
List choose = null;
Form form = new Form("收支情况");
//定义警告对话框
Alert alert = new Alert("消息", "已经成功清除所有记录!", null, AlertType.INFO);
static final Command cmdBack = new Command("Back", Command.BACK, 0);
static final Command cmdMainMenu = new Command("Main", Command.SCREEN, 1);
static final Command cmdSave = new Command("Save", Command.OK, 2);
static final Command cmdExit = new Command("Exit", Command.STOP, 3);
String currentMenu = null;
//记录存储对象
RecordStore rs = null;
// Form组件
DateField recordDate = new DateField("发生日期", DateField.DATE);
TextField inNumber = new TextField("收入金额", null, 50, TextField.ANY);
TextField outNumber = new TextField("支出金额", null, 20, TextField.NUMERIC);
public IncomeDemo() { // constructor
}
// 使用指定的名称打开记录存储
public RecordStore openRS(String fileName) {
try {
rs = RecordStore.openRecordStore(fileName, true);
} catch(RecordStoreException rse) {
rse.printStackTrace();
}
return rs;
}
// 关闭记录存储对象
public void closeRS() throws RecordStoreNotOpenException, RecordStoreException {
if (rs.getNumRecords() == 0) {
String fileName = rs.getName();
rs.closeRecordStore();
rs.deleteRecordStore(fileName);
}
else {
rs.closeRecordStore();
}
}
// 使用enumeration对象删除记录存储对象中的每一个记录
public void deleteRS() {
try {
RecordEnumeration re = enumerate();
while(re.hasNextElement()) {
int id = re.nextRecordId();
rs.deleteRecord(id);
}
showAlert();
} catch (Exception e) { }
}
// 获取enumeration对象
public synchronized RecordEnumeration enumerate() throws RecordStoreNotOpenException {
return rs.enumerateRecords(null, null, false);
}
//启动MIDlet
public void startApp() throws MIDletStateChangeException {
display = Display.getDisplay(this);
//打开记录存储对象
try {
openRS("income");
} catch(Exception e) {}
menu = new List("收支管理", Choice.IMPLICIT);
menu.append("添加 ", null);
menu.append("查看 ", null);
menu.append("删除", null);
menu.addCommand(cmdExit);
menu.setCommandListener(this);
form.append(inNumber);
form.append(recordDate);
form.append(outNumber);
mainMenu();
}
public void pauseApp() {
display = null;
choose = null;
menu = null;
form = null;
try {
closeRS();
} catch(Exception e) {}
}
public void destroyApp(boolean unconditional) {
try {
closeRS();
} catch(Exception e) {}
notifyDestroyed();
}
void mainMenu() {
display.setCurrent(menu);
currentMenu = "Main";
}
//显示警告对话框
public void showAlert()
{
try {
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert);
}
catch(Exception e) {}
}
// 将日期型数据转换成字符型
// 日期格式使用mm/dd/yyyy
public String dateTostr(Date dateVal) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(dateVal);
String strDate = Integer.toString (calendar.get(calendar.DAY_OF_MONTH));
String strMonth = Integer.toString (calendar.get(calendar.MONTH)+1);
String strYear = Integer.toString (calendar.get(calendar.YEAR));
return strMonth + "/" + strDate + "/" + strYear;
}
// 显示Form
public void addLoan () {
form.addCommand(cmdSave);
form.addCommand(cmdBack);
form.setCommandListener(this);
display.setCurrent(form);
currentMenu = "Add";
}
//将记录添加到记录存储对象
public synchronized void addNewLoan(String record) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream daos = new DataOutputStream(baos);
try {
daos.writeUTF(record);
}
catch (IOException ioe) {
System.out.println(ioe);
ioe.printStackTrace();
}
byte[] bytearr = baos.toByteArray();
try {
rs.addRecord(bytearr, 0, bytearr.length);
}
catch (RecordStoreException rse) {
System.out.println(rse);
rse.printStackTrace();
}
}
//显示记录存储对象中的还款详情
public void listItems() {
choose = new List("Repayment List", Choice.IMPLICIT);
choose.addCommand(cmdBack);
choose.setCommandListener(this);
try {
RecordEnumeration re = enumerate();
while(re.hasNextElement()) {
String theList = new String(re.nextRecord());
choose.append(theList, null);
}
} catch(Exception e) {}
display.setCurrent(choose);
currentMenu = "List";
}
// 事件处理
public void commandAction(Command c, Displayable d) {
String label = c.getLabel();
if (label.equals("Exit")) {
destroyApp(true);
} else if (label.equals("Save")) {
if(currentMenu.equals("Add")) {
// 添加贷款信息到记录存储
try {
String strNumber = inNumber.getString();
String strAmount = outNumber.getString();
String strDate = dateTostr (recordDate.getDate());
// 根据输入的信息创建记录
String strResult = strNumber + " ;" + strAmount + " ;" + strDate;
// 添加到记录存储对象中
addNewLoan(strResult);
} catch(Exception e) {}
mainMenu();
}
} else if (label.equals("Back")) {
if(currentMenu.equals("List")) {
//显示主菜单
mainMenu();
} else if(currentMenu.equals("Add")) {
// 显示主菜单
mainMenu();
}
} else {
List down = (List)display.getCurrent();
switch(down.getSelectedIndex()) {
case 0: addLoan();break;
case 1: listItems();break;
case 2: deleteRS();break;
}
}
}
}
--------------------编程问答-------------------- 代码好长啊
补充:Java , Java相关