当前页面: 开发资料首页 → J2ME 专题 → 封装多MIDIet程序
摘要: 封装多MIDIet程序
/*----------------------------------------------------
* www.CoreJ2ME.com
*
* Simple MIDlet1
*---------------------------------------------------*/
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class MIDlet1 extends MIDlet implements CommandListener
{
private Display display; // Reference to Display object
private TextBox tbxMain; // A Textbox to display a message
private Command cmdExit; // A Command to exit the MIDlet
// The constructor
public MIDlet1()
{
display = Display.getDisplay(this);
cmdExit = new Command("Exit", Command.SCREEN, 1);
tbxMain = new TextBox("Welcome", "Core J2ME", 50, 0);
tbxMain.addCommand(cmdExit);
tbxMain.setCommandListener(this);
}
// Called by application manager to start the MIDlet.
public void startApp()
{
display.setCurrent(tbxMain);
}
// A required method
public void pauseApp()
{ }
// A required method
public void destroyApp(boolean unconditional)
{ }
// Check to see if our Exit command was selected
public void commandAction(Command c, Displayable s)
{
if (c == cmdExit)
{
destroyApp(false);
notifyDestroyed();
}
}
}
/*----------------------------------------------------
* www.CoreJ2ME.com
*
* Simple MIDlet2
*---------------------------------------------------*/
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class MIDlet2 extends MIDlet implements CommandListener
{
private Display display; // Reference to Display object
private Form frmMain; // The main form
private TextField txfName; // A text field to prompt for name
private Command cmdExit; // A Command to exit the MIDlet
// The constructor
public MIDlet2()
{
display = Display.getDisplay(this);
cmdExit = new Command("Exit", Command.SCREEN, 1);
txfName = new TextField("Name:", "", 10, TextField.ANY);
frmMain = new Form("Sample Form");
frmMain.addCommand(cmdExit);
frmMain.append(txfName);
frmMain.setCommandListener(this);
}
// Called by application manager to start the MIDlet.
public void startApp()
{
display.setCurrent(frmMain);
}
// A required method
public void pauseApp()
{ }
// A required method
public void destroyApp(boolean unconditional)
{ }
// Check to see if our Exit command was selected
public void commandAction(Command c, Displayable s)
{
if (c == cmdExit)
{
destroyApp(false);
notifyDestroyed();
}
}
}
bruceyuki,JAVA C#技术爱好者,现就读于新西兰奥克兰大学,正参与大学的一个AI项目,可以点击http://www.matrix.org.cn/user_view.asp?username=bruceyuki查看他的个人信息