package test01;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import com.siemens.mp.gsm.SMS;
import com.siemens.mp.NotAllowedException;
import java.io.IOException;
import com.siemens.mp.io.*;
public class StartMIDlet extends MIDlet
{
static StartMIDlet instance;
UIMainList MainList = new UIMainList();
public StartMIDlet()
{
instance = this;
}
public void startApp() throws MIDletStateChangeException
{
try
{
Display.getDisplay(this).setCurrent(MainList);
}
catch(Exception e)
{
System.out.println("e = "+e);
}
}
public void pauseApp()
{
}
public void destroyApp(boolean UIcondition)
{
}
public static void quitApp()
{
instance.destroyApp(true);
instance.notifyDestroyed();
instance = null;
}
}
class UIMainList extends List
{
private static String[] Str_List = {"A",
"B",
"C"};
static Displayable instance = null;
private Command cmExit;
private Command cmInfo;
public UIMainList() //throws Exception
{
super("测试",
List.IMPLICIT,
Str_List,
null);
setCommandListener(new CommandListener()
{
public void commandAction(Command c, Displayable d)
{
DisplayCommand(c,d);
}
}
);
cmInfo = new Command("Help", 1, 1);
cmExit = new Command("Exit", 1, 2);
jbInit();
instance = this;
temp_run();
}
public void temp_run() //throws Exception
{
Receiver rec = new Receiver();
Connection con = new Connection ("SMS: 223322332");
Alert str = new Alert("fail");
try
{
con.setListener(rec);
//把上面这句注释后程序能跑,一打开模拟器就死。为什么?
//没有这句,我就监听不到短信的到来啊
}
catch(Exception e)
{
Display.getDisplay(StartMIDlet.instance).setCurrent(str);
}
}
public void DisplayCommand(Command c,Displayable d)
{
if(c == cmExit)
{
instance = null;
StartMIDlet.quitApp();
}
else if( c == cmInfo)
{
Alert Al = new Alert("Help");
Al.setString("测试的帮助文件");
Display.getDisplay(StartMIDlet.instance).setCurrent(Al);
}
}
private void jbInit()
{
addCommand(cmInfo);
addCommand(cmExit);
}
}
class Receiver implements ConnectionListener
{
public void receiveData(byte[] data)
{
try
{
Alert str = new Alert("sms succ");
Display.getDisplay(StartMIDlet.instance).setCurrent(str);
}
catch(Exception e)
{
Alert str = new Alert("sms fail");
Display.getDisplay(StartMIDlet.instance).setCurrent(str);
}
}
}
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import com.siemens.mp.gsm.SMS;
import com.siemens.mp.NotAllowedException;
import java.io.IOException;
import com.siemens.mp.io.*;
public class StartMIDlet extends MIDlet
{
static StartMIDlet instance;
UIMainList MainList = new UIMainList();
public StartMIDlet()
{
instance = this;
}
public void startApp() throws MIDletStateChangeException
{
try
{
Display.getDisplay(this).setCurrent(MainList);
}
catch(Exception e)
{
System.out.println("e = "+e);
}
}
public void pauseApp()
{
}
public void destroyApp(boolean UIcondition)
{
}
public static void quitApp()
{
instance.destroyApp(true);
instance.notifyDestroyed();
instance = null;
}
}
class UIMainList extends List
{
private static String[] Str_List = {"A",
"B",
"C"};
static Displayable instance = null;
private Command cmExit;
private Command cmInfo;
public UIMainList() //throws Exception
{
super("测试",
List.IMPLICIT,
Str_List,
null);
setCommandListener(new CommandListener()
{
public void commandAction(Command c, Displayable d)
{
DisplayCommand(c,d);
}
}
);
cmInfo = new Command("Help", 1, 1);
cmExit = new Command("Exit", 1, 2);
jbInit();
instance = this;
temp_run();
}
public void temp_run() //throws Exception
{
Receiver rec = new Receiver();
Connection con = new Connection ("SMS: 223322332");
Alert str = new Alert("fail");
try
{
con.setListener(rec);
//把上面这句注释后程序能跑,一打开模拟器就死。为什么?
//没有这句,我就监听不到短信的到来啊
}
catch(Exception e)
{
Display.getDisplay(StartMIDlet.instance).setCurrent(str);
}
}
public void DisplayCommand(Command c,Displayable d)
{
if(c == cmExit)
{
instance = null;
StartMIDlet.quitApp();
}
else if( c == cmInfo)
{
Alert Al = new Alert("Help");
Al.setString("测试的帮助文件");
Display.getDisplay(StartMIDlet.instance).setCurrent(Al);
}
}
private void jbInit()
{
addCommand(cmInfo);
addCommand(cmExit);
}
}
class Receiver implements ConnectionListener
{
public void receiveData(byte[] data)
{
try
{
Alert str = new Alert("sms succ");
Display.getDisplay(StartMIDlet.instance).setCurrent(str);
}
catch(Exception e)
{
Alert str = new Alert("sms fail");
Display.getDisplay(StartMIDlet.instance).setCurrent(str);
}
}
}