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

📄 eboardservant.java

📁 远程网络画板,用JAVA RMI实现,远程的多个用户可以同时在同一画板上绘画
💻 JAVA
字号:
package whiteboard;
import java.rmi.*;
import java.util.Vector;
import java.rmi.server.UnicastRemoteObject;
import javax.swing.table.*;



public class eboardServant extends UnicastRemoteObject implements eboard
{
	public Vector customerList;
	private Vector itemList;
        //private Vector eraserList;
	private int count=0;
      //  public drawings eraser;
	
	
	public eboardServant() throws RemoteException
	{
		customerList=new Vector();
		itemList=new Vector();
        /*        Pencil anitem=new Pencil();
                anitem.x1=0;
                anitem.y1=0;
                anitem.x2=100;
                 anitem.y2=100;
                 anitem.stroke =1.0f;
                anitem.R =120;
                 anitem.G =120;
                  anitem.B =120;
                                                                                        
                 anitem.type=3;
                itemList.add(anitem);*/
          //      customerList.add(new parcel(new Callback,count,name));
     //   eboardServer.addmodel.addRow(new Object[]{count,name, new Boolean(false)});
                
                
	}
	
        public Vector getCustomerList()
        {
            return customerList;
        }
        
  	public void add(drawings g) throws RemoteException
  	{
  		itemList.add(g);
  		for(int i=0;i<customerList.size();i++)
  		{
  		    try{
  		    	CallBack cb=((parcel)(customerList.elementAt(i))).callback;
  		    	cb.callback(((parcel)(customerList.elementAt(i))).connectStatus);
  		    }catch(Exception e)
  		    {
  		    	;
  		    }	
  		}
  		System.out.println("new drawings coming");
  	}

	public void load(Vector all)
	{
		itemList = all;
		System.out.println("sdasdasdsadsa   size is " + all.size());
		for (int i = 0; i < customerList.size(); i++)
		{
			try
			{
				CallBack cb = ((parcel)(customerList.elementAt(i))).callback;
				cb.callback(((parcel)(customerList.elementAt(i))).connectStatus);
			}
			catch (Exception e)
			{
				;
			}
		}
	}


	public void newFile() throws RemoteException
	{

		Vector temp= new Vector();
		itemList=temp;
		for (int i = 0; i < customerList.size(); i++)
		{
			try
			{
				CallBack cb = ((parcel)(customerList.elementAt(i))).callback;
				cb.callback(((parcel)(customerList.elementAt(i))).connectStatus);
			}
			catch (Exception e)
			{
				;
			}
		}
		System.out.println("new drawings coming");
	}






        
     	public void notifyit(int id) throws RemoteException
  	{
  	
  		
  		    try{
  		    	CallBack cb=((parcel)(customerList.elementAt(id))).callback;
  		    	cb.callback(((parcel)(customerList.elementAt(id))).connectStatus);
  		    }catch(Exception e)
  		    {
  		    	;
  		    }	
  		
  	}
        public void notifyitwarning(int id,String message){
             try{
  		    	CallBack cb=((parcel)(customerList.elementAt(id))).callback;
  		    	cb.callback(message);
  		    }catch(Exception e)
  		    {
  		    	;
  		    }	
        }


	public void notifyallwarning( String message)
	{
		try
		{
			for (int i = 1; i < customerList.size(); i++)
			{

				CallBack cb = ((parcel)(customerList.elementAt(i))).callback;
				cb.callback(message);
			}
		}
		catch (Exception e)
		{
			;
		}
	}

        
        
        
    public Vector getall()throws RemoteException
    {
    	return itemList;
    }
    
    
      /*	public void addEraser(drawings g) throws RemoteException
  	{
  		eraserList.add(g);
  		for(int i=0;i<customerList.size();i++)
  		{
  		    try{
  		    	CallBack cb=((parcel)(customerList.elementAt(i))).callback;
  		    	cb.callback(((parcel)(customerList.elementAt(i))).connectStatus);
  		    }catch(Exception e)
  		    {
  		    	;
  		    }	
  		}
  		System.out.println("new drawings coming");
  	}*/
    
   /* public Vector getEraser()throws RemoteException
   {
    	return eraserList;
   }*/
    
    public boolean getConnectStatus(int id) {
    	for(int i=0;i<customerList.size();i++)
    	{
    		if(((parcel)(customerList.elementAt(i))).tag==id) 
                {
        return ((parcel)(customerList.elementAt(i))).connectStatus;
                }
        }
        return false;
    }
    
    public int regist(CallBack callback, String name) throws RemoteException
    {
    	//customerList.add(new parcel(callback,count,name));
        if(name.compareTo("SERVER") == 0) {
            customerList.add(new parcel(callback,count,name));
        eboardServer.model.addRow(new Object[]{count,name,new Boolean(false)});
        }
        else {
        customerList.add(new parcel(callback,count,name));
        eboardServer.addmodel.addRow(new Object[]{count,name, new Boolean(false)});
        }
        /*
        if(count%2==1) {
            ((parcel)(customerList.elementAt(count))).connectStatus=true;
        }
         **/
  	/*	for(int i=0;i<customerList.size();i++)
  		{
  		    try{
  		    	CallBack cb=((parcel)(customerList.elementAt(i))).callback;
  		    	
                        cb.callback(false);
  		    }catch(Exception e)
  		    {
  		    	;
  		    }	
  		}*/
    	
    	System.out.println("new custommer coming");
    	
    	int temp=count;
    	count=(count+1)%1000;
    	
    	return temp;
    }
    
    public void deregist(int callbackid) throws RemoteException
    {
   
    	for(int i=0;i<customerList.size();i++)
    	{
    		if(((parcel)(customerList.elementAt(i))).tag==callbackid) 
                {
                    
                    System.out.println("this " + ((parcel)(customerList.elementAt(i))).connectStatus);
                    // if the it has a status false , then search from  addmodel table
                    if (!((parcel)(customerList.elementAt(i))).connectStatus)
                    {
                        for(int j=0;j<eboardServer.addmodel.getRowCount();j++) 
                        {
                            System.out.println(((Integer)eboardServer.addmodel.getValueAt(j,0)).intValue()); 
                            if (((Integer)eboardServer.addmodel.getValueAt(j,0)).intValue() == callbackid)
                            {
                                eboardServer.addmodel.removeRow(j);
                            }
                        }
                    }
                    
                    //other wise search from model table
                    else 
                    {
                    
                        for(int j=0;j<eboardServer.model.getRowCount();j++) 
                        {
                            System.out.println(((Integer)eboardServer.model.getValueAt(j,0)).intValue()); 
                            if (((Integer)eboardServer.model.getValueAt(j,0)).intValue() == callbackid)
                            {
                                eboardServer.model.removeRow(j);
                            }
                        }
                        
                    }
                    
    		    customerList.remove(i);
                }
    	}
    
    	System.out.println("one custommer leave");
    }
    
    public void clear() throws RemoteException
    {
    	itemList.clear();
 
  		for(int i=0;i<customerList.size();i++)
  		{
  		    try{
  		    	CallBack cb=((parcel)(customerList.elementAt(i))).callback;
  		    	cb.callback(true);
  		    }catch(Exception e)
  		    {
  		    	;
  		    }	
  		}
  		System.out.println("clear");    	
    }
}

class parcel
{
	CallBack callback;
	int tag;
        String name;     
        boolean connectStatus=false;
        	public parcel(CallBack cback,int t,String name)
	{
		callback=cback;
		tag=t;
                this.name=name;
                if (name.compareTo("SERVER") == 0)
                {
                    connectStatus=true;
                }
	}
	public parcel(CallBack cback,int t)
	{
		callback=cback;
		tag=t;
         
	}
        /*
        public void getConnectStatus(int id)
        {
            
        }*/
        public void setConnectStatus(boolean connected)
        {
            this.connectStatus=connected;
        }
}

⌨️ 快捷键说明

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