1、使用NETBEANS做为开发工具,使用可视化设计器。几乎不用写代码,可以完成两个界面的转向之类的基本操作,以帮助系统为例。
2、程序效果
3、NETBEANS自动生成的代码
package hello;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class HelloMIDlet extends MIDlet implements CommandListener{
private boolean midletPaused = false;
//
private Command exitCommand;
private Command helpCommand;
private Command backCommand;
private Command exitCommand1;
private Form form;
private StringItem stringItem;
private TextBox HELPMSG_TB;
//
public HelloMIDlet() {
}
//
//
//
private void initialize() {
// write pre-initialize user code here
// write post-initialize user code here
}
//
//
public void startMIDlet() {
// write pre-action user code here
switchDisplayable(null, getForm());
// write post-action user code here
}
//
//
public void resumeMIDlet() {
// write pre-action user code here
switchDisplayable(null, getForm());
// write post-action user code here
}
//
//
public void switchDisplayable(Alert alert, DisplayablenextDisplayable) {
// write pre-switch user code here
Display display = getDisplay();
if (alert == null) {
display.setCurrent(nextDisplayable);
} else {
display.setCurrent(alert, nextDisplayable);
}
// write post-switch user code here
}
//
//
public void commandAction(Command command, Displayable displayable){
// write pre-action user code here
if (displayable == HELPMSG_TB) {
if (command == backCommand) {
// write pre-action user code here
switchDisplayable(null, getForm());
// write post-action user code here
} else if (command == exitCommand1) {
// write pre-action user code here
exitMIDlet();
// write post-action user code here
}
} else if (displayable == form) {
if (command == exitCommand) {
// write pre-action user code here
exitMIDlet();
// write post-action user code here
} else if (command == helpCommand) {
// write pre-action user code here
switchDisplayable(null, getHELPMSG_TB());
// write post-action user code here
}
}
// write post-action user code here
}
//
//
public Command getExitCommand() {
if (exitCommand == null) {
// write pre-init user code here
exitCommand = new Command("/u9000/u51FA", Command.EXIT, 0);
// write post-init user code here
}
return exitCommand;
}
//
//
public Form getForm() {
if (form == null) {
// write pre-init user code here
form = new Form("Welcome", new Item[] { getStringItem() });
form.addCommand(getExitCommand());
form.addCommand(getHelpCommand());
form.setCommandListener(this);
// write post-init user code here
}
return form;
}
//
//
public StringItem getStringItem() {
if (stringItem == null) {
// write pre-init user code here
stringItem = newStringItem("/u6382/u82B1/u5FAE/u7B11/u7684/u535A/u5BA2","/u8F6F/u4EF6/u5F00/u53D1/u57FA/u5730/u6B22/u8FCE/u60A8/u7684/u5230/u6765");
// write post-init user code here
}
return stringItem;
}
//
//
public Command getStopCommand() {
if (stopCommand == null) {
// write pre-init user code here
stopCommand = new Command("/u505C/u6B62", Command.STOP, 0);
// write post-init user code here
}
return stopCommand;
}
//
//
public Command getCancelCommand() {
if (cancelCommand == null) {
// write pre-init user code here
cancelCommand = new Command("/u53D6/u6D88", Command.CANCEL,0);
// write post-init user code here
}
return cancelCommand;
}
//
//
public Command getHelpCommand() {
if (helpCommand == null) {
// write pre-init user code here
helpCommand = new Command("/u5E2E/u52A9", Command.HELP, 0);
// write post-init user code here
}
return helpCommand;
}
//
//
public Command getBackCommand() {
if (backCommand == null) {
// write pre-init user code here
backCommand = new Command("/u8FD4/u56DE", Command.BACK, 0);
// write post-init user code here
}
return backCommand;
}
//
//
public Command getExitCommand1() {
if (exitCommand1 == null) {
// write pre-init user code here
exitCommand1 = new Command("/u9000/u51FA", Command.EXIT, 0);
// write post-init user code here
}
return exitCommand1;
}
//
//
public TextBox getHELPMSG_TB() {
if (HELPMSG_TB == null) {
// write pre-init user code here
HELPMSG_TB = new TextBox("textBox","/u8F6F/u4EF6/u5F00/u53D1/u57FA/u5730/u535A/u5BA2/u5E2E/u52A9/u7CFB/u7EDF~~/n/u6309/u8FD4/u56DE/u952E/u9000/u51FA/u5E2E/u52A9",100, TextField.ANY);
HELPMSG_TB.addCommand(getBackCommand());
HELPMSG_TB.addCommand(getExitCommand1());
HELPMSG_TB.setCommandListener(this);
// write post-init user code here
}
return HELPMSG_TB;
}
//
public Display getDisplay () {
return Display.getDisplay(this);
}
public void exitMIDlet() {
switchDisplayable (null, null);
destroyApp(true);
notifyDestroyed();
}
public void startApp() {
if (midletPaused) {
resumeMIDlet ();
} else {
initialize ();
startMIDlet ();
}
midletPaused = false;
}
public void pauseApp() {
midletPaused = true;
}
public void destroyApp(boolean unconditional) {
}
}