rmi
Class ChatClient

java.lang.Object
  extended by java.rmi.server.RemoteObject
      extended by java.rmi.server.RemoteServer
          extended by java.rmi.server.UnicastRemoteObject
              extended by rmi.ChatParticipant
                  extended by rmi.ChatClient
All Implemented Interfaces:
java.io.Serializable, java.rmi.Remote, ChatClientInterface, ChatParticipantInterface

public class ChatClient
extends ChatParticipant
implements ChatClientInterface

Class for client for simple chat program. An object of this class provides the functionality needed to communicate with the server and other clients; the user interface is provided by an object of a class implementing the ChatClientUI interface.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class rmi.ChatParticipant
clients, errorPrefix, serverPrefix
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Constructor Summary
ChatClient(java.lang.String name, java.lang.String serverHost, ChatClientUI ui)
          Constructs client object, querying server for a list of other clients and displaying this information.
 
Method Summary
 void addClient(ChatClientInterface c)
          Adds client, displaying some info about the new client.
 void display(java.lang.String message)
          Displays message, using whatever method is provided by the user interface for the client.
 java.lang.String getAddress()
          Gets client's hostname/IPA.
 java.lang.String getMessagePrefix()
          Gets prefix for messages broadcast by this object.
 java.lang.String getScreenName()
          Gets client's screen name.
 void removeClient(ChatClientInterface c)
          Removes client, displaying some info about it.
 void shutdown()
          Shuts down, notifying server that we're leaving.
 void startup()
          Starts up.
 
Methods inherited from class rmi.ChatParticipant
broadcast
 
Methods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, unexportObject
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toString, toStub
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface rmi.ChatParticipantInterface
broadcast
 

Constructor Detail

ChatClient

public ChatClient(java.lang.String name,
                  java.lang.String serverHost,
                  ChatClientUI ui)
           throws java.rmi.RemoteException,
                  java.rmi.NotBoundException,
                  java.net.MalformedURLException
Constructs client object, querying server for a list of other clients and displaying this information.

Parameters:
name - screen name
serverHost - host where server is running
ui - user interface for client (provides something on which to display messages, etc.)
Throws:
java.rmi.RemoteException
java.rmi.NotBoundException
java.net.MalformedURLException
Method Detail

addClient

public void addClient(ChatClientInterface c)
               throws java.rmi.RemoteException
Adds client, displaying some info about the new client.

Specified by:
addClient in interface ChatParticipantInterface
Overrides:
addClient in class ChatParticipant
Parameters:
c - client to add
Throws:
java.rmi.RemoteException

removeClient

public void removeClient(ChatClientInterface c)
                  throws java.rmi.RemoteException
Removes client, displaying some info about it.

Specified by:
removeClient in interface ChatParticipantInterface
Overrides:
removeClient in class ChatParticipant
Parameters:
c - client to remove
Throws:
java.rmi.RemoteException

getScreenName

public java.lang.String getScreenName()
                               throws java.rmi.RemoteException
Gets client's screen name.

Specified by:
getScreenName in interface ChatClientInterface
Returns:
screen name
Throws:
java.rmi.RemoteException

getAddress

public java.lang.String getAddress()
                            throws java.rmi.RemoteException
Gets client's hostname/IPA.

Specified by:
getAddress in interface ChatClientInterface
Returns:
hostname and IPA, in string form
Throws:
java.rmi.RemoteException

display

public void display(java.lang.String message)
             throws java.rmi.RemoteException
Displays message, using whatever method is provided by the user interface for the client.

Specified by:
display in interface ChatParticipantInterface
Parameters:
message - message to display
Throws:
java.rmi.RemoteException

startup

public void startup()
             throws java.rmi.RemoteException
Starts up.

Specified by:
startup in interface ChatClientInterface
Throws:
java.rmi.RemoteException

shutdown

public void shutdown()
              throws java.rmi.RemoteException
Shuts down, notifying server that we're leaving.

Specified by:
shutdown in interface ChatClientInterface
Throws:
java.rmi.RemoteException

getMessagePrefix

public java.lang.String getMessagePrefix()
Gets prefix for messages broadcast by this object.

Specified by:
getMessagePrefix in class ChatParticipant
Returns:
prefix for messages (screen name)