1. Where do I start?
The first place to start is getting your client to log in to the server. This is accomplished with a method call on a ChatModel object:
mod.logIn(nickname)Your program must first get the name that your user wants to use as a nickname, and then call this method. The ChatModel object used should be the one created in the main method.
Note: Since you are using the ChatModel created in the main method, your log in procedures must happen after the main method has finished. If you try to log your user in while constructing a ChatView object, it won't work: the ChatModel for your program will not yet be created.
The next steps would include:
2. I think I am logging in right, but when I try it nothing happens.
Why don't I get a response?
If you are logging in correctly, you probably are getting a response. But you must register a listener with your ChatModel object in order to hear the response. Once you use the ChatModel to log in correctly, some time after that the ChatModel will be told by the server that the log in was okay, and will call the method
serverResponded(ChatEvent ev)on any ChatListeners registered with it. You must have a class in your program that implements the ChatListener interface and add an object from that class as a listener to the chat model. It is recommended that you have the ChatView class itself implement ChatListener and add itself as a listener to the ChatModel.
3. I tried writing a ChatModel class, but I don't understand how to
make it talk to the server?
You do not need to write a ChatModel class. This class is already defined in the package chatclient, so to create a ChatModel object all you need to do is import chatclient.* , just as you import javax.swing.* in order to create objects defined in the swing package. Likewise, the classes Channel, ChatEvent, ChannelEvent, ChatListener, and ChannelListener are already defined in the chatclient package.
4. I tried to find an "add" method to my JList, but I couldn't find
one. How do I add something to it?
You do not add to a JList directly. You add and remove single elements to the model for the JList. A JList can have three different types of model: an array of Objects, a Vector, or a DefaultListModel. When you update the model of your JList, your JList will reflect the changes to its model. The API documentation for a JList (which is in the swing package) has examples of how to use JLists.
5. When I add to the data of a JList, it shows up twice in the list.
Why?
When you are provided with a list of either channels or users on a channel, you are provided with a string array containing the entire current list. If you are simply adding the items from this array to your model, chances are you are duplicating the same names over and over again. Try clearing the contents of your list model first.
6. I keep getting a "class ChatView must be declared abstract..."
error when I compile. Why does it say this?
You are probably implementing an interface with your ChatView class, but have not overridden all of the methods defined in the interface. Remember that in order to have a class implement an interface, it must give an implementation for each of the methods in that interface. If you don't do this, (or if you thought you did but had a misspelling in the method definitions), the compiler will tell you that your class has not properly implemented all of the abstract methods in the interface and should therefor be declared an abstract class.
7. Sometimes when I run my program, I get a "NullPointerException"
and then a bunch of lines of cryptic information. What does all of it
mean, and why is it happening?
The lines being printed is the trace of all of the methods that were called from the time the exception occurred to the time that exception was propagated up to the Java Runtime system. The first line of the stack print is the place where the problem occurred in your program (it tells you exactly which method, in which class, is causing the problem.)
A NullPointerException occurs when you try to call a method on a variable that has been declared, but not assigned to an actual object yet. Example:
class A {
ChatModel m;
public void method(){
m.doSomething();
}
}
If m.doSomething() is called before m has been assigned to an actual
object, a NullPointerException is thrown.
8. When I try to log in, I get a "Connection Refused" message. Why?
There are two possibilities: the server is not running on the machine your program is trying to connect with, or the server is down. The first problem should never happen if you are running on the Unix system, but if you are running your program at home you may need to get a new copy of the jar file containing the chatclient package. This can be found at
/group/yoyo/22c20/on the Unix system network and can be ftp'd to your machine at home. If the server is down, we apologize, and simply ask that you email one of the TA's and we will restart the server as soon as possible.
9. I tried using the "getUserList()" method of the Channel class to get
the user list for a Channel. Why doesn't this work?
The only method you should ever call on the Channel class is
passOutMessage(String msg, String nick)
userListChanged(ChannelEvent ev)
String[] names = (String[])event.getContent();
10. I have hooked up a listener to my ChatModel object, but I don't
understand what to do with all of the methods in the ChatModel interface.
When do I use them?
Although you need to override all of the methods in the interface, the only ones that you need to worry about are:
channelListProvided(ChatEvent ev)
serverResponded(ChatEvent ev)
The second will be called when the server is confirming a login or notifying you of an error.
11. I am confused about joining a channel. I understand that I must
create a new Channel object when my user says they want to join a channel,
but I don't understand what to do next.
In general, the following things should be done in your program when the user wants to join a new channel:
mod.openChannel(String nickname, Channel channel)
12. I understand how to join a channel, but can I create one? If so, how
do I do that?
Yes, you can create a channel, but doing so is no different than joining a channel. If you join a channel that does not exist, the server will automatically create it and place you on it.
NOTES:
Remember that in order to send information to the server, you call methods on one of two objects, either a ChatModel object or one of your Channel objects (you must create one of these for each channel your user joins).
In the ChatModel class, the only methods you should ever need to use are:
logIn(String) logOut(String) openChannel(String,Channel) closeChannel(String,Channel) requestChannelListUpdate(String)In the Channel class, the only method you should ever need to use is:
passOutMessage(String,String)
ChatListener:
serverResponded(ChatEvent) channelListProvided(ChatEvent)ChannelListener:
inMessageReceived(ChannelEvent) userListChanged(ChannelEvent)In each case, the information relative to the event occurring is contained within the actual event object passed in to the method. You do not use the Channel and ChatModel class to get the information you need, you use the event. The methods in the ChatEvent and ChannelEvent class that you use are:
getContent()-- returns either a String or a String[] in the form of an Object.
getSender()- returns a String
getType()- returns an int
By implementing the interfaces and using these three methods on the event objects, you can obtain all of the information you need about communication coming into your program from the server.