Class MsgUser

java.lang.Object
  extended by MsgUser
All Implemented Interfaces:
java.lang.Comparable<MsgUser>

public class MsgUser
extends java.lang.Object
implements java.lang.Comparable<MsgUser>

Represents a Java Messenger user.


Constructor Summary
MsgUser(Server theServer, java.lang.String name, java.lang.String pswd)
          Constructs a new user with a given screen name and password.
 
Method Summary
 void addBuddy(MsgUser u)
          If myWindow is initialized, adds u to its set of buddies by calling myWindow.addBuddy(u).
 int compareTo(MsgUser other)
          Compares this user to another by comparing their screen names case blind.
 boolean equals(java.lang.Object other)
          Indicates whether some other user is "equal to" this one, based on comparing their screen names case blind.
 java.lang.String getName()
          Returns the screen name for this user.
 java.lang.String getPassword()
          Returns the password for this user.
 void openDialog(java.util.Set<MsgUser> buddies)
          Creates a new MsgWindow for this user and saves a reference to it in myWindow.
 void quit()
          Logs out this user by calling server.logout(this).
 void receiveMessage(java.lang.String text)
          If myWindow is initialized, shows the received message by calling myWindow.showMessage(text).
 void removeBuddy(MsgUser u)
          If myWindow is initialized, removes u from its set of buddies by calling myWindow.removeBuddy(u).
 java.lang.String toString()
          Returns this user's screenName.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MsgUser

public MsgUser(Server theServer,
               java.lang.String name,
               java.lang.String pswd)
Constructs a new user with a given screen name and password.

Parameters:
theServer - the server for this user.
name - user name.
pswd - password.
Method Detail

getName

public java.lang.String getName()
Returns the screen name for this user.

Returns:
the screen name for this user.

getPassword

public java.lang.String getPassword()
Returns the password for this user.

Returns:
the pasword for this user.

compareTo

public int compareTo(MsgUser other)
Compares this user to another by comparing their screen names case blind.

Specified by:
compareTo in interface java.lang.Comparable<MsgUser>
Parameters:
other - the reference to a user with which to compare.
Returns:
the result of the comparison of this user and other.

equals

public boolean equals(java.lang.Object other)
Indicates whether some other user is "equal to" this one, based on comparing their screen names case blind. This method will throw a ClassCastException if other is not an instance of user.

Overrides:
equals in class java.lang.Object
Parameters:
other - the reference to an object with which to compare.
Returns:
true if this user's screen name is the same as other's; false otherwise.

openDialog

public void openDialog(java.util.Set<MsgUser> buddies)
Creates a new MsgWindow for this user and saves a reference to it in myWindow.

Parameters:
buddies - the set of this user's buddies.

addBuddy

public void addBuddy(MsgUser u)
If myWindow is initialized, adds u to its set of buddies by calling myWindow.addBuddy(u).

Parameters:
u - a buddy to be added.

removeBuddy

public void removeBuddy(MsgUser u)
If myWindow is initialized, removes u from its set of buddies by calling myWindow.removeBuddy(u).

Parameters:
u - a buddy to be removed.

receiveMessage

public void receiveMessage(java.lang.String text)
If myWindow is initialized, shows the received message by calling myWindow.showMessage(text).

Parameters:
text - a message to be displayed.

quit

public void quit()
Logs out this user by calling server.logout(this). (This method is called from the MsgWindow's window listener when the "close window" button is clicked.)


toString

public java.lang.String toString()
Returns this user's screenName.

Overrides:
toString in class java.lang.Object