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, String n) {
35 serv.AddClientThread(this);
37 TheArea.setLayout(new GridLayout(25,1));
39 for (a=0; a<25; ++a) {
40 Linez[a] = new Label(" ");
41 Linez[a].setBackground(Color.black);
42 Linez[a].setForeground(Color.black);
43 TheArea.add(Linez[a]);
50 private void ScrollIt(String TheNewLine, Color NewLineColor) {
51 for (a=0; a<24; ++a) {
52 Linez[a].setText(Linez[a+1].getText());
53 Linez[a].setForeground(Linez[a+1].getForeground());
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();
83 if (ST.hasMoreTokens()) {
84 cText = ST.nextToken();
89 if (!cText.startsWith("NOOP")) {
90 if (!LastLineUser.equals(cUser)) {
91 ScrollIt("", Color.black);
92 ThisLine = cUser + ": ";
95 ThisLine = " ".substring(0, cUser.length()+2);
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
121 ReceiveChat MyReceive;
127 MultiUserChat102(wcCitServer PrimaryServ, wcchat P) {
128 super ("Multiuser Chat");
132 /* Set up a new server connection as a piggyback to the first. */
137 setLayout(new BorderLayout());
139 boof = "This is the buffer before the chat command.";
140 serv.ServPuts("CHAT");
141 boof = serv.ServGets();
143 if (boof.charAt(0) != '8') {
144 add("Center", new Label("ERROR: " + boof) );
149 DoChat(PrimaryServ.GetUserName());
156 * Do the actual chat stuff
158 private void DoChat(String MyName) {
161 SendBox = new TextField(80);
163 AllUsers = new Panel();
165 add("Center", AllUsers);
166 add("South", SendBox);
169 MyReceive = new ReceiveChat(this, AllUsers, serv, MyName);
172 SendBox.requestFocus();
176 public boolean handleEvent(Event evt) {
179 if ( (evt.target == SendBox) && (evt.id == Event.ACTION_EVENT) ) {
180 serv.ServPuts(SendBox.getText());
184 else if (evt.target == SendBox) {
185 if ( SendBox.getText().length() + serv.GetUserName().length() > 78 ) {
186 LastSpace = SendBox.getText().lastIndexOf(' ');
188 serv.ServPuts(SendBox.getText());
192 serv.ServPuts(SendBox.getText().substring(0,LastSpace));
193 SendBox.setText(SendBox.getText().substring(LastSpace));
194 if (SendBox.getText().charAt(0) == ' ') {
195 SendBox.setText(SendBox.getText().substring(1));
201 return super.handleEvent(evt);