tofriendfile.java

来自「JAVA实现的聊天工具,可以容纳最多10个用户 1.本系统需要JDK1.5 」· Java 代码 · 共 63 行

JAVA
63
字号
//represent file to send to a friend 
import java.io.File;

class ToFriendFile  implements Comparable<ToFriendFile>{
	private int id;
	private File file;
	//public FileToFriend(){}
	public ToFriendFile(File file){
		this.file=file;
		id=ClientThread.getToFriendFileID();
	}
	
	public ToFriendFile(int id){
		this.id=id;
	}
	
	public int compareTo(ToFriendFile tff){
		boolean b=(id==tff.getID());
		return (b==true ? 0 : id>tff.getID() ? 1 : -1);
	}
	
	public int getID(){
		return id;
	}
	
	public File getFile(){
		return file;
	}
}
//represent file from a friend
class FromFriendFile implements Comparable<FromFriendFile>{
	private int sendFileKey,receiveFileKey;  //when receive a send-file request,assign it an receiveFileKey
	private File file;
	private String ip;
	//public FileToFriend(){}
	public FromFriendFile(File file,String ip,int sendFileKey){
		this.file=file;
		this.ip=ip;
		this.sendFileKey=sendFileKey;
		receiveFileKey=ClientThread.getFromFriendFileID();
	}
	
	public FromFriendFile(int receiveFileKey){
		this.receiveFileKey=receiveFileKey;
	}
	
	public int compareTo(FromFriendFile fcf){
		boolean b=(receiveFileKey==fcf.getID());
		return (b==true ? 0 : receiveFileKey>fcf.getID() ? 1 : -1);
	}
	
	public int getID(){
		return receiveFileKey;
	}
	
	public File getFile(){
		return file;
	}
	
	public String getIP(){
		return ip;
	}
}

⌨️ 快捷键说明

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