|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.Observable
ch.epfl.lpd.ids.client.ChatClient
public class ChatClient
This class represents a chat client. A chat client is responsible for creating its GUI as well as the two threads that will fetch new messages and the list of connected clients.
Field Summary | |
---|---|
protected ClientListFetcher |
clf
The reference to the ClientListFetcher that is responsible
for retrieving the list of the connected clients. |
protected boolean |
connected
Boolean used to check is this client is connected to the server or not. |
protected IWindowManager |
iw
The reference to the IWindowManager
in order to correctly dispose the ressources when the client is
closed. |
protected IServer |
server
The reference to the IServer . |
protected String |
username
The username of this chat client. |
Constructor Summary | |
---|---|
ChatClient(IServer server,
IWindowManager iw)
Creates a new instance of ChatClient. |
Method Summary | |
---|---|
void |
close()
Method called by ClientGUI when the
user close the chat GUI. |
boolean |
connect(String username)
Method called by the ClientGUI when
the user wants to connect to the server. |
boolean |
disconnect(String username)
Method called by the ClientGUI when
the user wants to disconnect from the IServer . |
void |
run()
Method called when a new thread representing this client is started. |
void |
sendMessage(IMessage msg)
Method called by the ClientGUI when
the user wants to send a message to the other chat
clients. |
Methods inherited from class java.util.Observable |
---|
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected IServer server
IServer
. This reference will be used to
send and receive messages.
protected IWindowManager iw
IWindowManager
in order to correctly dispose the ressources when the client is
closed.
protected String username
protected boolean connected
protected ClientListFetcher clf
ClientListFetcher
that is responsible
for retrieving the list of the connected clients.
Constructor Detail |
---|
public ChatClient(IServer server, IWindowManager iw)
ClientGUI
,
the ClientListFetcher
and
initialize the MVC.
server
- The IServer
reference.iw
- The reference to the IWindowManager
.Method Detail |
---|
public boolean connect(String username)
ClientGUI
when
the user wants to connect to the server. This method calls the
connect()
method on the IServer
connect
in interface IChatClient
username
- The username of the client.
public boolean disconnect(String username)
ClientGUI
when
the user wants to disconnect from the IServer
.
disconnect
in interface IChatClient
username
- The username of the client.
public void sendMessage(IMessage msg)
ClientGUI
when
the user wants to send a message to the other chat
clients. This method creates a new IMessage
and sends it to the
server.
sendMessage
in interface IChatClient
msg
- The message as a IMessage.public void close()
ClientGUI
when the
user close the chat GUI. This stops the different threads,
disconnects from the server and calls the IWindowManager
to inform it that it can
release the ressources for this chat client.
close
in interface IChatClient
public void run()
IBlockingQueue
on the server until a new
message is received. Once this message is received, it is put
in the GUI.
run
in interface Runnable
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |