j2me精解书籍代码j2me源代码很好的入门工具

源代码在线查看: sender.java

软件大小: 18837 K
上传用户: add505
关键词: j2me 书籍 代码 源代码
下载地址: 免注册下载 普通下载 VIP

相关代码

				package com.j2medev.ch6.socket;
				
				import javax.microedition.midlet.*;
				import javax.microedition.io.*;
				import javax.microedition.lcdui.*;
				import java.io.*;
				
				public class Sender extends Thread {
				  private DataOutputStream dos;
				    private String message;
				
				    public Sender(DataOutputStream dos) {
				        this.dos = dos;
				        start();
				    }
				
				    public synchronized void send(String msg) {
				        message = msg;
				        //唤醒线程,发送数据
				        notify();
				    }
				
				    public synchronized void run() {
				        while (true) {
				            //如果message=null那么等待
				            if (message == null) {
				                try {
				                    wait();
				                } catch (InterruptedException e) {
				                }
				            }
				            if (message == null) {
				                break;
				            }
				            try {
				                dos.writeUTF(message);
				            } catch (IOException ioe) {
				                ioe.printStackTrace();
				            }
				            message = null;
				        }
				    }
				    //停止
				    public synchronized void stop() {
				        message = null;
				        notify();
				    }
				}
				
							

相关资源