?? client.java
字號(hào):
/*
* @(#)Client.java 1.6 03/03/02
*
* Copyright (c) 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms
*/
package example.datagram;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import java.io.IOException;
public class Client implements Runnable, CommandListener {
private DatagramMIDlet parent;
private Display display;
private Form f;
private StringItem si;
private TextField tf;
private Command sendCommand = new Command("Send", Command.ITEM, 1);
Sender sender;
public Client(DatagramMIDlet m) {
parent = m;
display = Display.getDisplay(parent);
f = new Form("Datagram Client");
si = new StringItem("Status:" , " ");
tf = new TextField("Send:", "", 30, TextField.ANY);
f.append(si);
f.append(tf);
f.addCommand(sendCommand);
f.setCommandListener(this);
display.setCurrent(f);
}
public void start() {
Thread t = new Thread(this);
t.start();
}
public void run() {
try {
DatagramConnection dc = (DatagramConnection) Connector.open("datagram://localhost:5555");
si.setText("Connected to server");
sender = new Sender(dc);
while (true) {
Datagram dg = dc.newDatagram(100);
dc.receive(dg);
// Have we actually received something or is this just a timeout ?
if (dg.getLength() > 0) {
si.setText("Message received - " +
new String(dg.getData(), 0, dg.getLength()));
}
}
} catch (ConnectionNotFoundException cnfe) {
Alert a = new Alert("Client", "Please run Server MIDlet first",
null, AlertType.ERROR);
a.setTimeout(Alert.FOREVER);
display.setCurrent(a);
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
public void commandAction(Command c, Displayable s) {
if (c == sendCommand && !parent.isPaused()) {
sender.send(null, tf.getString());
}
}
public void stop() {
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -