LIST的简单问题,希望大家帮忙看看.

ZeroIsMyNo 2005-02-20 12:33:39
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class Interface extends MIDlet
implements CommandListener {

Display display;
List menu;
List choose;
Form helpinfo;
List input;
Form me;
Ticker ticker = new Ticker(
"Welcome to Map System!");
DateField date = new DateField("Today's date: ", DateField.DATE);
Form form = new Form("Form for Stuff");
Form today = new Form("Today's date");
Gauge gauge = new Gauge("Progress Bar", false, 20, 9);
TextField textfield = new TextField(
"TextField Label", "abc", 50, 0);
static final Command backCommand =
new Command("Back", Command.BACK, 0);
static final Command mainMenuCommand =
new Command("Main", Command.SCREEN, 1);
static final Command exitCommand =
new Command("Exit", Command.STOP, 2);
String currentMenu;


public Interface() {}


public void startApp() throws
MIDletStateChangeException {
display = Display.getDisplay(this);
menu = new List(
"Function List", Choice.IMPLICIT);
menu.append("Building List", null);
menu.append("View Date", null);
menu.append("Help", null);
menu.append("About Software", null);
menu.append("View Map", null);
menu.addCommand(exitCommand);
menu.setCommandListener(this);
menu.setTicker(ticker);
mainMenu();
form.append(gauge);
form.append(textfield);
// today
today.append(date);
}

public void pauseApp() {
display = null;
choose = null;
menu = null;
ticker = null;
form = null;
today = null;
input = null;
gauge = null;
textfield = null;
}

public void destroyApp(boolean unconditional) {
notifyDestroyed();
}


void mainMenu() {
display.setCurrent(menu);
currentMenu = "Main";
}




public void commandAction(Command c,
Displayable d) {
String label = c.getLabel();
if (label.equals("Exit")) {
destroyApp(true);
} else if (label.equals("Back")) {
if(currentMenu.equals("input")
|| currentMenu.equals("date")
|| currentMenu.equals("helpinfo")
|| currentMenu.equals("me")){
mainMenu();
}

} else {
List down = (List)display.getCurrent();
switch(down.getSelectedIndex()) {
case 0: BuildingList();break;
case 1: ViewDate();break;
case 2: Help();break;
case 3: AboutMe();break;

}

}
}
public void ViewDate() {
java.util.Date now = new java.util.Date();
date.setDate(now);
today.addCommand(backCommand);
today.setCommandListener(this);
display.setCurrent(today);
currentMenu = "date";
}
public void AboutMe() {
me = new Form("Software Introdution");
StringItem Intro1 = new StringItem
("Developer:", "YiHua Bao");
StringItem Intro2 = new StringItem
("StudentID:", "04912357");
StringItem Intro3 = new StringItem
("Year:", "2004-2005");
me.append(Intro1);
me.append(Intro2);
me.append(Intro3);
me.setTicker(new Ticker("Final Year Project"));
me.addCommand(backCommand);
me.setCommandListener(this);
display.setCurrent(me);
currentMenu = "me";
}
public void Help() {
helpinfo = new Form("Help Information");
StringItem Help1 = new StringItem
("View Description:", "Select the Bilding List option in the main menu->Select the Building you want->Select View Description Option.");
StringItem Help2 = new StringItem
("Search Building:", "Select the Bilding List option in the main menu->Select the Building you want->Select Show Building Option.");
StringItem Help3 = new StringItem
("View Map:", "Select the Building List option in the main menu->Use the Hotkey(Left, Right, Up, Down) to move the map.");
StringItem Help4 = new StringItem
("ZoomIn & ZoomOut:","Use the HotKey for ZoomIn & ZoomOut when the map is displayed.");
helpinfo.append(Help1);
helpinfo.append(Help2);
helpinfo.append(Help3);
helpinfo.append(Help4);
helpinfo.setTicker(new Ticker("Welcome to use Help"));
helpinfo.addCommand(backCommand);
helpinfo.setCommandListener(this);
display.setCurrent(helpinfo);
currentMenu = "helpinfo";
}
public void BuildingList() {
input = new List(
"Bilding List", Choice.IMPLICIT);
input.append("1. Lipman Building", null);
input.append("2. Squires Building", null);
input.append("3. Squires Annexe", null);
input.append("4. Newcastle College", null);
input.append("5. Library", null);
input.append("6. Art Gallery", null);
input.append("7. Student Service", null);
input.append("8. Students' Union", null);
input.append("9. Northumberland Building", null);
input.append("10. Northumbrialand Annexe", null);
input.append("11. College House", null);
input.append("12. Sutherland Building", null);
input.append("13. Trinity Building", null);
input.append("14. Ellison Building", null);
input.append("15. rutherford Hall", null);
input.append("16. Ellison terrace", null);
input.append("17. Wynne-Jones Center", null);
input.append("18. Pardon Building", null);
input.append("19. 21 & 22 Ellison Terrace", null);
input.append("20. Claude Gibb Hall", null);
input.append("21. Lovaine Hall", null);
input.append("22. Sport Centre", null);
input.append("23. Newcastle Unitarian Church", null);
input.append("24. St James' Church", null);
input.append("25. Health Center", null);
input.append("26. Burt Hall", null);
input.append("27. Glenamara House", null);
input.append("28. North Terrace", null);
input.append("29. Drill Hall", null);
input.append("30. Legal Service Unit", null);
input.append("31. SSR Centre", null);
input.append("32. Technopole", null);
input.append("33. Nixon Hall", null);
input.setTicker(new Ticker("Select The Building Here"));
input.addCommand(backCommand);
input.setCommandListener(this);
display.setCurrent(input);
currentMenu = "input";
}
}
当我进到BUILDINGLIST里面又会回到,MAINMENU的几个选项,怎样可以把他们分开并当我选XXXX BUDILING的时候有关于这个BUILDING的选项呢?
谢谢大家帮忙.
...全文
126 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
贝壳鱼 2005-02-21
  • 打赏
  • 举报
回复
*************************Interface.java***********************************

import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class Interface extends MIDlet
implements CommandListener {

Display display;
List menu0;
List choose;
Form helpinfo;

Form me;
Ticker ticker = new Ticker(
"Welcome to Map System!");
DateField date = new DateField("Today's date: ", DateField.DATE);
Form form = new Form("Form for Stuff");
Form today = new Form("Today's date");
Gauge gauge = new Gauge("Progress Bar", false, 20, 9);
TextField textfield = new TextField(
"TextField Label", "abc", 50, 0);
static final Command backCommand =
new Command("Back", Command.BACK, 0);
static final Command mainMenuCommand =
new Command("Main", Command.SCREEN, 1);
static final Command exitCommand =
new Command("Exit", Command.STOP, 2);
String currentMenu;


public Interface() {}


public void startApp() throws
MIDletStateChangeException {
display = Display.getDisplay(this);
menu0 = new List(
"Function List", Choice.IMPLICIT);
menu0.append("Building List", null);
menu0.append("View Date", null);
menu0.append("Help", null);
menu0.append("About Software", null);
menu0.append("View Map", null);
menu0.addCommand(exitCommand);
menu0.setCommandListener(this);
menu0.setTicker(ticker);
mainMenu();
form.append(gauge);
form.append(textfield);

today.append(date);
}

public void pauseApp() {
display = null;
choose = null;
menu0 = null;
ticker = null;
form = null;
today = null;

gauge = null;
textfield = null;
}

public void destroyApp(boolean unconditional) {
notifyDestroyed();
}

void mainMenu() {
display.setCurrent(menu0);
currentMenu = "Main";
}

public void commandAction(Command c,
Displayable d) {
String label = c.getLabel();
if (label.equals("Exit")) {
destroyApp(true);
} else if (label.equals("Back")) {
if(currentMenu.equals("date")
|| currentMenu.equals("helpinfo")
|| currentMenu.equals("me")){
mainMenu();
}

} else {
List down = (List)display.getCurrent();
switch(down.getSelectedIndex()) {
case 0: BuildingList();break;
case 1: ViewDate();break;
case 2: Help();break;
case 3: AboutMe();break;

}

}
}
public void ViewDate() {
java.util.Date now = new java.util.Date();
date.setDate(now);
today.addCommand(backCommand);
today.setCommandListener(this);
display.setCurrent(today);
currentMenu = "date";
}
public void AboutMe() {
me = new Form("Software Introdution");
StringItem Intro1 = new StringItem
("Developer:", "YiHua Bao");
StringItem Intro2 = new StringItem
("StudentID:", "04912357");
StringItem Intro3 = new StringItem
("Year:", "2004-2005");
me.append(Intro1);
me.append(Intro2);
me.append(Intro3);
me.setTicker(new Ticker("Final Year Project"));
me.addCommand(backCommand);
me.setCommandListener(this);
display.setCurrent(me);
currentMenu = "me";
}
public void Help() {
helpinfo = new Form("Help Information");
StringItem Help1 = new StringItem
("View Description:", "Select the Bilding List option in the main menu->Select the Building you want->Select View Description Option.");
StringItem Help2 = new StringItem
("Search Building:", "Select the Bilding List option in the main menu->Select the Building you want->Select Show Building Option.");
StringItem Help3 = new StringItem
("View Map:", "Select the Building List option in the main menu->Use the Hotkey(Left, Right, Up, Down) to move the map.");
StringItem Help4 = new StringItem
("ZoomIn & ZoomOut:","Use the HotKey for ZoomIn & ZoomOut when the map is displayed.");
helpinfo.append(Help1);
helpinfo.append(Help2);
helpinfo.append(Help3);
helpinfo.append(Help4);
helpinfo.setTicker(new Ticker("Welcome to use Help"));
helpinfo.addCommand(backCommand);
helpinfo.setCommandListener(this);
display.setCurrent(helpinfo);
currentMenu = "helpinfo";
}
public void BuildingList()
{
BuildingList bl = new BuildingList(display,menu0);
display.setCurrent(bl);

}
}
*****************************************************************************************
*********************************BuildingList.java****************************************

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class BuildingList extends List
implements CommandListener
{
private Display dis;
private Displayable disa;
private Command backCommand = new Command("BACK",Command.BACK,1);
public BuildingList(Display d,Displayable s)
{
super("Bilding List", Choice.IMPLICIT);
this.append("1. Lipman Building", null);
this.append("2. Squires Building", null);
this.append("3. Squires Annexe", null);
this.append("4. Newcastle College", null);
this.append("5. Library", null);
this.append("6. Art Gallery", null);
this.append("7. Student Service", null);
this.append("8. Students' Union", null);
this.append("9. Northumberland Building", null);
this.append("10. Northumbrialand Annexe", null);
this.append("11. College House", null);
this.append("12. Sutherland Building", null);
this.append("13. Trinity Building", null);
this.append("14. Ellison Building", null);
this.append("15. rutherford Hall", null);
this.append("16. Ellison terrace", null);
this.append("17. Wynne-Jones Center", null);
this.append("18. Pardon Building", null);
this.append("19. 21 & 22 Ellison Terrace", null);
this.append("20. Claude Gibb Hall", null);
this.append("21. Lovaine Hall", null);
this.append("22. Sport Centre", null);
this.append("23. Newcastle Unitarian Church", null);
this.append("24. St James' Church", null);
this.append("25. Health Center", null);
this.append("26. Burt Hall", null);
this.append("27. Glenamara House", null);
this.append("28. North Terrace", null);
this.append("29. Drill Hall", null);
this.append("30. Legal Service Unit", null);
this.append("31. SSR Centre", null);
this.append("32. Technopole", null);
this.append("33. Nixon Hall", null);
this.setTicker(new Ticker("Select The Building Here"));
dis = d;
disa = s;
addCommand(backCommand);
setCommandListener(this);
}
public void commandAction(Command c,Displayable d)
{
if(c == backCommand)
{
dis.setCurrent(disa);
}
}
}
*****************************************************************************************

以上代码在WTK2.1中,编译通过,可以运行,,,把你的第一个菜单和BuildingList菜单分开了,呵呵.
贝壳鱼 2005-02-21
  • 打赏
  • 举报
回复
行,等我给你改改,然后发到这里吧。晚上发过来!
ZeroIsMyNo 2005-02-21
  • 打赏
  • 举报
回复
谢谢啦,我现在有概念了,我现在郁闷了也喝水了
bonbonice 2005-02-20
  • 打赏
  • 举报
回复
是啊
贝壳鱼 2005-02-20
  • 打赏
  • 举报
回复
当我进到BUILDINGLIST里面又会回到,MAINMENU的几个选项,怎样可以把他们分开并当我选XXXX BUDILING的时候有关于这个BUILDING的选项呢?
----------------------------------------------------------------------------------

你能否说清楚点?看了20分钟,不知道你想要做什么!

而且你这样写有问题,进入buildinglist里面,选择前四项,跟你前一个画面的选项有相同的作用,所以你应该写在两个类里面。
ZeroIsMyNo 2005-02-20
  • 打赏
  • 举报
回复
和和,高手们不好意思,我刚刚开始学J2ME,思路还很混乱.
K7SEM给我个例子教教我怎么做好吗?谢谢

13,097

社区成员

发帖
与我相关
我的任务
社区描述
Java J2ME
社区管理员
  • J2ME社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧