📄 wmaclient.java
字号:
package ch09.section06;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import javax.wireless.messaging.*;
import java.io.*;
import java.lang.*;
import java.util.*;
public class WMAClient
extends MIDlet
implements CommandListener, MessageListener {
private Command exitCommand;
private Command sendMsgCommand;
private Display display;
Form displayForm;
String msgToSend = "Can you hear me?";
MessageConnection clientConn;
public WMAClient() {
display = Display.getDisplay(this);
exitCommand =
new Command("Exit", Command.SCREEN, 1);
sendMsgCommand =
new Command("Send", Command.SCREEN, 1);
}
public void notifyIncomingMessage(MessageConnection conn) {
}
public void startApp() {
displayForm = new Form("Send Message");
displayForm.addCommand(exitCommand);
displayForm.addCommand(sendMsgCommand);
displayForm.setCommandListener(this);
displayForm.setItemStateListener(this);
display.setCurrent(displayForm);
try {
clientConn = (MessageConnection) Connector.open(
"sms://+18643630999 : 5000");
}
catch (IOException ioExc) {
System.out.println("Client connection could not be obtained");
ioExc.printStackTrace();
}
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
public void commandAction(
Command c, Displayable s) {
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
if (c == sendMsgCommand) {
try {
TextMessage tmsg =
(TextMessage) clientConn.newMessage
(MessageConnection.TEXT_MESSAGE);
tmsg.setAddress("sms://18643630999:5000");
tmsg.setPayloadText(msgToSend);
clientConn.send(tmsg);
}
catch (Exception exc) {
exc.printStackTrace();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -