?? sender.java
字號:
import javax.microedition.midlet.*;import javax.microedition.io.*;import javax.microedition.lcdui.*;import java.io.*;public class Sender extends Thread { private OutputStream os; private String message; public Sender(OutputStream os) { /*得到父類的輸出流*/ this.os = os; start(); } public synchronized void send(String msg) { /*得到父類的傳輸值*/ message = msg; notify(); } public synchronized void run() { while(true) { /*如果傳輸的數據沒有被接收,則等待*/ if (message == null) { try { wait(); } catch (InterruptedException e) { } } if (message == null) { break; }/*利用輸出流傳出數據,如果傳到了目的端,則結束傳輸*/ try { os.write(message.getBytes()); os.write("\n".getBytes()); stop(); } catch (IOException ioe) { ioe.printStackTrace(); } /* 標記,以用來重新傳輸*/ message = null; } }/*結束傳輸*/ public synchronized void stop() { message = null; notify(); }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -