|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.rit.chat2.Chat
public class Chat
Class Chat is a rudimentary M2MI-based chat application. The program displays a simple chat UI (an instance of class ChatFrame), and the program exports a chat object (an instance of class Chat) that implements interface ChatRef. Each chat room is associated with its own multihandle for interface ChatRef, and the chat object is attached to the multihandle corresponding to the chat room the user joined. When the user sends a line of text in the UI, the line is broadcast to all the chat objects in the chat room by calling putLine() on the multihandle. When each chat object receives a putLine() invocation, it displays the line of text in the chat log in its UI.
To discover which chat rooms are out there, the chat object also implements interface ChatDiscoveryRef. Each chat object periodically broadcasts the name and multihandle of its chat room by calling reportChatRoom() on an omnihandle for interface ChatDiscoveryRef. When each chat object receives a reportChatRoom() invocation, it puts the chat room name and multihandle in a list. When the user selects a chat room, the chat object detaches itself from the previous chat room's multihandle and attaches itself to the new chat room's multihandle.
The chat demo is intended merely to demonstrate M2MI omnihandle and multihandle invocations and is not intended to be a full-featured chat application.
Usage: java edu.rit.chat2.Chat username
When running the chat demo application, M2MI and M2MP must be configured, and the M2MP Daemon must be running if necessary. See packages edu.rit.m2mi and edu.rit.m2mp for further information.
The chat demo application displays this UI:
Pick the chat room to join from the drop-down list, or click the "New..." button to create a new chat room. Type a line of text into any chat window on any machine and hit return or click the "Send" button. The line of text, prefixed by the user name, shows up in all the chat windows on all the machines that have joined the same chat room.
Method Summary | |
---|---|
void |
action(Timer theTimer)
Upon timeout, broadcast the existence of this chat room. |
static void |
main(String[] args)
Main program. |
void |
newChatRoom()
Report that the user wants to create a new chat room. |
void |
putMessage(String line)
Display the given line of text in this chat object's chat log. |
void |
reportChatRoom(ChatRoom theChatRoom)
Report that a chat room exists. |
void |
requestChatRooms()
Request everyone to report the existence of their chat rooms. |
void |
run(String[] args)
Run this chat application. |
void |
send(String line)
Process the given line of text entered by the user. |
void |
setChatRoom(int i)
Report that the user selected the given chat room. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public void run(String[] args) throws Throwable
args
- Command line arguments.
Throwable
public void newChatRoom()
newChatRoom
in interface ChatFrameListener
public void setChatRoom(int i)
setChatRoom
in interface ChatFrameListener
i
- Chat room index.public void send(String line)
send
in interface ChatFrameListener
line
- Line of text.public void putMessage(String line)
putMessage
in interface ChatRef
line
- Line of text.public void requestChatRooms()
requestChatRooms
in interface ChatDiscoveryRef
public void reportChatRoom(ChatRoom theChatRoom)
reportChatRoom
in interface ChatDiscoveryRef
theChatRoom
- Chat room (name plus multihandle).public void action(Timer theTimer)
action
in interface TimerTask
theTimer
- Timer.public static void main(String[] args) throws Throwable
args
- Command line arguments.
Throwable
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |