📄 smssend.java
字号:
import javax.microedition.midlet.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.wireless.messaging.*;
import java.io.IOException;
public class SMSSend extends MIDlet
implements CommandListener {
Command exitCommand = new Command("Exit", Command.EXIT, 2);
Command okCommand = new Command("OK", Command.OK, 1);
Display display;
String smsPort;
TextBox destinationAddressBox;
Alert errorMessageAlert;
Alert sendingMessageAlert;
SMSSender sender;
Displayable resumeScreen = null;
public SMSSend() {
smsPort = getAppProperty("SMS-Port");
display = Display.getDisplay(this);
destinationAddressBox = new TextBox("目标地址",
null, 256, TextField.PHONENUMBER);
destinationAddressBox.addCommand(exitCommand);
destinationAddressBox.addCommand(okCommand);
destinationAddressBox.setCommandListener(this);
errorMessageAlert = new Alert("SMS", null, null, AlertType.ERROR);
errorMessageAlert.setTimeout(5000);
sendingMessageAlert = new Alert("SMS", null, null, AlertType.INFO);
sendingMessageAlert.setTimeout(5000);
sendingMessageAlert.setCommandListener(this);
sender = new SMSSender(smsPort, display, destinationAddressBox,
sendingMessageAlert);
resumeScreen = destinationAddressBox;
}
public void startApp() {
display.setCurrent(resumeScreen);
}
public void pauseApp() {
resumeScreen = display.getCurrent();
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable s) {
try {
if (c == exitCommand || c == Alert.DISMISS_COMMAND) {
destroyApp(false);
notifyDestroyed();
} else if (c == okCommand) {
promptAndSend();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
private void promptAndSend() {
String address = destinationAddressBox.getString();
if (!SMSSend.isValidPhoneNumber(address)) {
errorMessageAlert.setString("电话号码");
display.setCurrent(errorMessageAlert, destinationAddressBox);
return;
}
String statusMessage = "发消息给 " + address + "...";
sendingMessageAlert.setString(statusMessage);
sender.promptAndSend("sms://" + address);
}
private static boolean isValidPhoneNumber(String number) {
char[] chars = number.toCharArray();
if (chars.length == 0) {
return false;
}
int startPos = 0;
if (chars[0]=='+') {
startPos = 1;
}
for (int i = startPos; i < chars.length; ++i) {
if (!Character.isDigit(chars[i])) {
return false;
}
}
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -