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

📄 drawsend.java

📁 自己编写的一个java电子白板程序
💻 JAVA
字号:
package wbClient;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;

import java.io.*;
public class DrawSend extends Thread{

	public DataOutputStream io_out;
	public DataInputStream io_in;
	private final int SERVER_PORT = 5678;
	public MyClass myClass;
	public DrawSend(MyClass myClass){

		this.myClass = myClass;
	}
	public void run(){
		connectServer();
		drawReceive();
	}
	
	public void connectServer(){
		try{
			SocketConnection connection = (SocketConnection)Connector.open("socket://59.64.158.197:"+SERVER_PORT);
			connection.setSocketOption(SocketConnection.KEEPALIVE, 5);
			connection.setSocketOption(SocketConnection.DELAY, 0);
			connection.setSocketOption(SocketConnection.LINGER, 0);
			io_in = connection.openDataInputStream();
			io_out = connection.openDataOutputStream();

		}catch(IOException ioe){
			ioe.printStackTrace();
		}
		myClass.connected = true;
	}
	public void drawReceive(){
		while(myClass.connected){
			try{
				DataBag dataBag = new DataBag(0,0,0,0,0,true,0);
				dataBag.color = io_in.readInt();
				dataBag.sX = io_in.readInt();
				dataBag.sY = io_in.readInt();
				dataBag.eX = io_in.readInt();
				dataBag.eY = io_in.readInt();
				dataBag.commandCenter = io_in.readInt();
				dataBag.received = true;
//				dataBags.addElement(dataBag);
				myClass.commandCenter(dataBag,dataBag.commandCenter);
//				canvas.repaint();
			}catch(IOException ioe){
			//	ioe.printStackTrace();
				myClass.exit();
			}
		}
	}
	public void exitSend(){
		try{
			if(io_in != null){
				io_in.close();
			}
			if(io_out != null){
				io_out.close();
			}
			}catch(IOException ioe){
				ioe.printStackTrace();
			}
	}
	public void send(DataBag data){
		DataBag dataBag = data;
		try{
		io_out.writeInt(dataBag.color);
		io_out.writeInt(dataBag.sX);
		io_out.writeInt(dataBag.sY);
		io_out.writeInt(dataBag.eX);
		io_out.writeInt(dataBag.eY);
		io_out.writeInt(dataBag.commandCenter);
		}catch(IOException ioe){
			ioe.printStackTrace();
		}
	}


}
class DataBag {
	int color;
	int sX=0;
	int sY=0;
	int eX=0;
	int eY=0;
	boolean received = false;
	int commandCenter;
	public DataBag(int color,int sX,int sY,int eX,int eY,boolean received,int commandCenter){
		this.color = color;
		this.sX = sX;
		this.sY = sY;
		this.eX = eX;
		this.eY = eY;
		this.received = received;
		this.commandCenter= commandCenter;
	}
}

⌨️ 快捷键说明

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