J2ME中2个以上界面的编程

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) {
}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值