2 * MultiUserChat102.java
12 * ReceiveChat implements a thread which listens on the server socket and
13 * display anything which comes across the wire in the Panel specified
16 class ReceiveChat extends Thread {
26 MultiUserChat102 ParentMUC;
27 Label[] Linez = new Label[25];
30 ReceiveChat(MultiUserChat102 muc, Panel t, wcCitServer s,
36 serv.AddClientThread(this);
38 TheArea.setLayout(new GridLayout(25, 1));
40 for (a = 0; a < 25; ++a) {
41 Linez[a] = new Label(" ");
42 Linez[a].setBackground(Color.black);
43 Linez[a].setForeground(Color.black);
44 TheArea.add(Linez[a]);
49 private void ScrollIt(String TheNewLine, Color NewLineColor) {
50 for (a = 0; a < 24; ++a) {
51 Linez[a].setText(Linez[a + 1].getText());
52 Linez[a].setForeground(Linez[a + 1].
55 Linez[24].setText(TheNewLine);
56 Linez[24].setForeground(NewLineColor);
66 boof = serv.ServGets();
68 if (boof.equals("000")) {
69 serv.ServPuts("QUIT");
76 ST = new StringTokenizer(boof, "|");
77 if (ST.hasMoreTokens()) {
78 cUser = ST.nextToken();
82 if (ST.hasMoreTokens()) {
83 cText = ST.nextToken();
87 if (!cText.startsWith("NOOP")) {
88 if (!LastLineUser.equals(cUser)) {
89 ScrollIt("", Color.black);
90 ThisLine = cUser + ": ";
97 ThisLine = ThisLine + cText;
98 UserColor = Color.green;
99 if (cUser.equals(":")) {
100 UserColor = Color.red;
102 if (cUser.equalsIgnoreCase(MyName)) {
103 UserColor = Color.yellow;
105 ScrollIt(ThisLine, UserColor);
106 LastLineUser = cUser;
117 public class MultiUserChat102 extends Frame {
120 ReceiveChat MyReceive;
126 MultiUserChat102(wcCitServer PrimaryServ, wcchat P) {
127 super("Multiuser Chat");
131 /* Set up a new server connection as a piggyback to the first. */
136 setLayout(new BorderLayout());
138 boof = "This is the buffer before the chat command.";
139 serv.ServPuts("CHAT");
140 boof = serv.ServGets();
142 if (boof.charAt(0) != '8') {
143 add("Center", new Label("ERROR: " + boof));
148 DoChat(PrimaryServ.GetUserName());
155 * Do the actual chat stuff
157 private void DoChat(String MyName) {
160 SendBox = new TextField(80);
162 AllUsers = new Panel();
164 add("Center", AllUsers);
165 add("South", SendBox);
168 MyReceive = new ReceiveChat(this, AllUsers, serv, MyName);
171 SendBox.requestFocus();
175 public boolean handleEvent(Event evt) {
178 if ((evt.target == SendBox)
179 && (evt.id == Event.ACTION_EVENT)) {
180 serv.ServPuts(SendBox.getText());
184 else if (evt.target == SendBox) {
185 if (SendBox.getText().length() +
186 serv.GetUserName().length() > 78) {
188 SendBox.getText().lastIndexOf(' ');
190 serv.ServPuts(SendBox.getText());
193 serv.ServPuts(SendBox.getText().
196 SendBox.setText(SendBox.getText().
199 if (SendBox.getText().charAt(0) ==
201 SendBox.setText(SendBox.
210 return super.handleEvent(evt);