📄 expenses.java
字号:
/*
Expenses
A sample J2ME MIDP application that illustrates the use
of List and Command UI components
Copyright 2002 CNet Networks
*/
package ExpensesApp;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.Vector;
public class Expenses extends MIDlet implements CommandListener {
private Display display;
private Vector expenseItems;
private List lsMain;
private Command cmAdd, cmEdit, cmExit, cmMenu;
private int itemCount = 0;
public Expenses() {
display = Display.getDisplay(this);
//get some play data
expenseItems = ExpenseInfo.LoadExpenses();
itemCount = expenseItems.size();
//Setup the UI
lsMain = new List("Expenses", List.IMPLICIT) ;
cmAdd = new Command("New", Command.SCREEN, 3);
cmEdit = new Command("Edit", Command.ITEM, 2);
cmExit = new Command("Exit", Command.EXIT, 1);
lsMain.addCommand(cmAdd);
lsMain.addCommand(cmEdit);
lsMain.addCommand(cmExit);
lsMain.setCommandListener(this);
//add all the Expense items to lsMain
rebuildList();
}
public void startApp() throws MIDletStateChangeException {
//Show the main UI form
display.setCurrent(lsMain);
}
public void commandAction(Command cm, Displayable d) {
if (cm == List.SELECT_COMMAND || cm == cmEdit) {
//User selected an item in lsMain or
//invoked the "Edit" command from the menu
//Edit an item, we'll implement this later
} else if (cm == cmAdd) {
//User invoked the "Add" command from the menu
//Add a new item, we'll implement this later
} else if (cm == cmExit) {
//User invoked the "Exit" command
destroyApp(false);
notifyDestroyed();
}
}
public void pauseApp() {
}
public void destroyApp(boolean b) {
}
private void rebuildList(){
//add all the expense items to lsMain
for(int i=0; i<expenseItems.size(); i++){
if (expenseItems.elementAt(i) != null){
ExpenseInfo exp = (ExpenseInfo) expenseItems.elementAt(i);
lsMain.append(exp.getDescription(),null);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -