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

📄 reader.java

📁 一个电子白版程序,J2me程序,注意,使用EC开发,要安装WTK和其插件才能使用
💻 JAVA
字号:
/*
 * Created on 2006-2-18
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
import java.io.DataInputStream;
import java.io.InputStream;

import javax.microedition.io.Connector;
import javax.microedition.io.SocketConnection;

/**
 * @author blrc
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class Reader extends Thread {
	
	private static final int bye = -100;

	ShareCanvas parent;
	SocketConnection currentConnection;
	InputStream is;
	DataInputStream dis;
	
	public Reader(ShareCanvas parent,SocketConnection currentConnection,InputStream is,DataInputStream dis) {
		super();
		this.parent = parent;
		this.currentConnection = currentConnection;
		this.is = is;
		this.dis = dis;		
	}
	
	public Reader(ShareCanvas parent,SocketConnection currentConnection)
	{
		super();
		this.parent = parent;
		this.currentConnection = currentConnection;
		try
		{
			is = currentConnection.openInputStream();
			dis = new DataInputStream(is);
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		
	}
	
	public void run()
	{
		while (true)
		{
			Dimension dimension = new Dimension();
			try
			{
				System.out.println("Reader is waiting here!");
				dimension.x = dis.readInt();
				dimension.y = dis.readInt();
			}
			catch(Exception e)
			{
				e.printStackTrace();
			}
			if (dimension.x == bye && dimension.y == bye)
			{
				System.out.println("Reader receive bye, then break!");
				break;
			}
			if (dimension.x ==  -1 && dimension.y == -1)
			{
				System.out.println("Reader receive -1,-1 and call canvas repaint");
				parent.repaint();
			}
			else
			{				
				parent.other.addElement(dimension);				
			}			
		}
		try
		{
			System.out.println("after break, Reader dis & is be close()");
			dis.close();
			is.close();
			Singal.ReaderAlive = false;
			if (Singal.WriterAlive == false)
			{
				System.out.println("at last, currentConnection be close()");
				currentConnection.close();
				parent.set_share(false);
			}
			else 
			{
				parent.showByeGUI();
				parent.cancelWriter();
				parent.revertCommand();
			}
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
}

⌨️ 快捷键说明

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