dd.util
Interface Chat

All Known Implementing Classes:
ChatPanel, NetClient

public interface Chat

A simple client-server chat interface. This interface is meant to support chat, real-time textual instant messages. This interface should be implemented by classes that support chat messages.

This interface has two parts, for clients and servers. A client (something that shows a chat user interface) should implement the gotChatMessage(java.lang.String, java.lang.String) method. It will be notified with this method whenever a new incoming chat message is received. A server (something that communicates with the network) should implement the sendChatMessage(java.lang.String, java.lang.String) method. This method will be called by clients that want to send outgoing chat messages.

Although both clients and servers must implement both methods in the chat interface, the client and server need not be the same component. In these cases, the client or server message should do nothing, and the user of this class is responsible for calling the appropriate chat client and server. For example:

 public class NetworkUtility implements Chat {
   public void sendChatMessage(String user, String message) {
     // Send the request over the network
   }
   public void gotChatMessage(String user, String message) {
     // Does nothing, or perhaps notifies clients
   }
 }
 public class MyUserInterface implements Chat {
   private Chat myServer; 
   public MyUserInterface(Chat server) {
     myServer = server;
   }
   public void sendChatMessage(String user, String message) {
     myServer.sendChatMessage(user, message);
   }
   public void gotChatMessage(String user, String message) {
     // update the UI
   }
   public void userEventHandler() {
     // call this.sendChatMessage() with appropriate info provided by
     // the user
   }
 }
 

Author:
Eric Scharff

Method Summary
 void gotChatMessage(java.lang.String user, java.lang.String message)
          Called when a chat message is received.
 void sendChatMessage(java.lang.String user, java.lang.String message)
          Sends a chat message over the network.
 

Method Detail

sendChatMessage

public void sendChatMessage(java.lang.String user,
                            java.lang.String message)
Sends a chat message over the network. This method should be implemented by chat servers. The expected result of this call is that the chat message will be broadcast appropriately to the other clients on the network.

Parameters:
user - name of the user who sent the message
message - chat message that to be sent

gotChatMessage

public void gotChatMessage(java.lang.String user,
                           java.lang.String message)
Called when a chat message is received. This method serves as notificaiton, a kind of event handler. When a chat message is sent over the network, this method should be called (by the network layer) to all clients that wish to be notified that a new chat message was sent. Typically the result of this call will be to prompt the user of a new incoming message.

Parameters:
user - name of the user who sent the message
message - chat message that was sent