如何在j2me中从另一个java程序显示父midlet
我正在开发一个 j2me 应用程序,其中有一个调用其他 java 程序的父 midlet。父 midlet 是包含 4 个元素的隐式列表。单击任何元素后,就会调用适当的 java 程序。一切工作正常,但我不明白如何在单击后退按钮时从 java 程序显示父 midlet。
请举例说明。 这是我的父 midlet 代码
package hello;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import java.io.*;
public class Contacts extends MIDlet implements CommandListener,Runnable {
Display display=null;
private Form form=new Form("Contacts");
private List menu=new List("Contact Menu",Choice.IMPLICIT);
private Command exit = new Command("Exit", Command.EXIT, 2);
private Command ok=new Command("Ok",Command.SCREEN,1);
private Command back = new Command("Back", Command.BACK, 1);
private Alert alert;
public Contacts()
{
display = Display.getDisplay(this);
try{
menu.append("Add Contact", Image.createImage("/contact_new.png"));
menu.append("Delete Contact",Image.createImage("/delete-icon.png"));
menu.append("Get Contact",Image.createImage("/document-edit.png"));
menu.append("View Contacts",Image.createImage("/view.png"));
menu.addCommand(ok);
menu.addCommand(exit);
menu.setCommandListener(this);
}
catch(IOException ie)
{
}
}
public void startApp() {
display.setCurrent(menu);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command command, Displayable displayable) {
if (command == exit) {
destroyApp(true);
notifyDestroyed();
return;
}
switch (menu.getSelectedIndex ()) {
case 0:
new ac (this);//call to java program
break;
case 1:
new dc (this);
break;
case 2:
new gc(this);
break;
case 3:
new vc(this);
break;
default:
System.err.println ("Unexpected choice...");
break;
}
}
}
I am developing a j2me application where there is one parent midlet which calls other java programs. Parent midlet is of implicit list which contains 4 elements. On clicking any of the elements an appropriate java program is called. Everything is working fine, but i don't understand how to show parent midlet from java program on clicking of back button.
Please provide examples.
this is my parent midlet code
package hello;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import java.io.*;
public class Contacts extends MIDlet implements CommandListener,Runnable {
Display display=null;
private Form form=new Form("Contacts");
private List menu=new List("Contact Menu",Choice.IMPLICIT);
private Command exit = new Command("Exit", Command.EXIT, 2);
private Command ok=new Command("Ok",Command.SCREEN,1);
private Command back = new Command("Back", Command.BACK, 1);
private Alert alert;
public Contacts()
{
display = Display.getDisplay(this);
try{
menu.append("Add Contact", Image.createImage("/contact_new.png"));
menu.append("Delete Contact",Image.createImage("/delete-icon.png"));
menu.append("Get Contact",Image.createImage("/document-edit.png"));
menu.append("View Contacts",Image.createImage("/view.png"));
menu.addCommand(ok);
menu.addCommand(exit);
menu.setCommandListener(this);
}
catch(IOException ie)
{
}
}
public void startApp() {
display.setCurrent(menu);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command command, Displayable displayable) {
if (command == exit) {
destroyApp(true);
notifyDestroyed();
return;
}
switch (menu.getSelectedIndex ()) {
case 0:
new ac (this);//call to java program
break;
case 1:
new dc (this);
break;
case 2:
new gc(this);
break;
case 3:
new vc(this);
break;
default:
System.err.println ("Unexpected choice...");
break;
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道标准 J2ME 中有任何 API 可以在 MIDlet 之间进行交互。至少已经发布了。有一些诺基亚专用 API 可以执行此类操作。
I don't know any API in standard J2ME to interact between MIDlets. At least that is already released. There is some Nokia private API to do some such kind of operations.