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

📄 displaymessage.java

📁 rmi chat that connects two or more clients
💻 JAVA
字号:

import java.rmi.*;
import java.rmi.server.*;

public class DisplayMessage extends UnicastRemoteObject implements Notify {

	private javax.swing.JTextArea textArea;
	private String name;

    public DisplayMessage(javax.swing.JTextArea ta)
        throws RemoteException {
    	    textArea = ta;
    }
    
    public void joinMessage(String name)
        throws RemoteException
    {
        try {
    	    textArea.append(name + " has joined\n");
    	}
        catch(Exception e){
            System.out.println("Message Failure");
            e.printStackTrace();
        };
    }
    
    public void sendMessage(String name, String message) throws RemoteException
    {
        try {
    	    textArea.append(name + " says: " + message + "\n");
    	}
        catch(Exception e){
            System.out.println("Message Failure");
            e.printStackTrace();
        };
    }
    
    public void exitMessage(String name) throws RemoteException {
        try {
    	    textArea.append(name + " has left the building.\n");
    	}
        catch(Exception e){
            System.out.println("Message Failure");
        };
    }
    
    //Notice this one not called remotely
    public void setName(String name) throws RemoteException {
    	this.name = name;
    }
    
    public String getName() {
    	return name;
    }
}

⌨️ 快捷键说明

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