⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sendsms.txt

📁 在sun的主页上找到的基于java me开发的移动发短信,很适用。
💻 TXT
字号:
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.wireless.messaging.*;
import javax.microedition.io.*;

public class SmsSend extends MIDlet implements CommandListener{
public Display display;
public static Form messageForm;
public static Form mainForm;
public static Command exitCommand;
public static Command backCommand;
public static Command sendCommand;
public static TextField address_tf;
public static TextField port_tf;
public static TextField message_text_tf;
String[] binary_str = {"Send BINARY message"};
public static ChoiceGroup binary_cg;
byte[] binary_data = {1, 2, 3, 4, 5, 6, 7, 8, 9};
String address;
String text;
MessageConnection conn = null;
TextMessage txt_message = null;
BinaryMessage bin_message = null;

public SmsSend() {
address_tf = new TextField("Address:", "", 32, TextField.PHONENUMBER);
port_tf = new TextField("Port:", "1000", 32, TextField.PHONENUMBER);
message_text_tf = new TextField("Message text:", "test message", 160,
TextField.ANY); binary_cg = new ChoiceGroup(null, Choice.MULTIPLE,
binary_str, null);
display = Display.getDisplay(this);
messageForm = new Form("SMS_send");
mainForm = new Form("SMS_send");
exitCommand = new Command("Exit", Command.EXIT, 0); backCommand = new
Command("Back", Command.BACK, 0); sendCommand = new Command("Send",
Command.ITEM, 1);
mainForm.append(address_tf); mainForm.append(port_tf);
mainForm.append(message_text_tf); mainForm.append(binary_cg);
mainForm.addCommand(exitCommand); mainForm.addCommand(sendCommand);
mainForm.setCommandListener(this);
messageForm.addCommand(backCommand);
messageForm.setCommandListener(this);
}
public void pauseApp(){ }
protected void startApp() {
display.setCurrent(mainForm);
}
public void destroyApp(boolean unconditional) {
notifyDestroyed();
}
public void showMessage(String s) {
if( messageForm.size() != 0 )
messageForm.delete(0);
messageForm.append(s);
display.setCurrent(messageForm);
}
public void commandAction(Command c, Displayable s) {
if((c == backCommand) && (s == messageForm)){
display.setCurrent(mainForm);
}
if((c == exitCommand) && (s == mainForm)) {
destroyApp(false);
}
if((c == sendCommand) && (s == mainForm)) {
address = "sms://" + address_tf.getString();
if(port_tf.size() != 0) address += ":" + port_tf.getString();
text = message_text_tf.getString();
new send_thread().start();
}
}
// inner class?
public class send_thread extends Thread {
public void run(){
try {
conn = (MessageConnection) Connector.open(address);
if(!binary_cg.isSelected(0)) {
txt_message = (TextMessage)
conn.newMessage(MessageConnection.TEXT_MESSAGE);
txt_message.setPayloadText(text);
conn.send(txt_message);
} else {
bin_message = (BinaryMessage)
conn.newMessage(MessageConnection.BINARY_MESSAGE);
bin_message.setPayloadData(binary_data);
conn.send(bin_message);
}
conn.close();
showMessage("Message sent");
} catch (Throwable t) {
showMessage("Unexpected " + t.toString() + ": " + t.getMessage());
}
}
}
// end SmsSend
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -