fork download
  1. // クライアントプログラム
  2.  
  3. import java.io.*;
  4. import java.util.*;
  5. import java.net.*;
  6. import javax.swing.*;
  7.  
  8. class MessageWindow extends JFrame {
  9. JTextArea textArea;
  10. MessageWindow() {
  11. super("Messages");
  12. textArea = new JTextArea(25, 80);
  13. textArea.setEditable(false);
  14. add(textArea);
  15. pack();
  16. setVisible(true);
  17. }
  18.  
  19. public void printMessage(String message) {
  20. textArea.append(message+"\n");
  21. }
  22. }
  23.  
  24.  
  25. public class ChatCl {
  26. public static void main(String[] args) {
  27. byte[] buf = new byte[ChatParam.MSIZE];
  28. byte[] send = new byte[ChatParam.MSIZE];
  29. byte[] cbuf;
  30. String str;
  31.  
  32. if (args.length < 2) {
  33. System.out.println("引数: サーバ名 ユーザ名");
  34. System.exit(1);
  35. }
  36.  
  37. try {
  38. /* サーバへの接続処理 */
  39.  
  40. String name = args[1];
  41.  
  42. System.out.println("[Input]----------------------------------");
  43.  
  44. MessageWindow mwin = new MessageWindow();
  45.  
  46. // 最初に参加要求(+ユーザ名)の送信
  47. send[0] = ChatParam.JOIN;
  48. cbuf = name.getBytes();
  49. System.arraycopy(cbuf, 0, send, 1, (cbuf.length < ChatParam.NSIZE)?cbuf.length:ChatParam.NSIZE);
  50.  
  51.  
  52. boolean flag = false;
  53. // 以下は他の参加者からのメッセージを受信する部分ですが、現状は
  54. // flagをfalseにして処理をスキップしています。
  55. while (flag) {
  56.  
  57. // メッセージを受信して、bufの中に保存
  58.  
  59. switch (buf[0]) {
  60. case ChatParam.LEAVE:
  61. str = new String(buf, 1, ChatParam.MSIZE - 1);
  62. mwin.printMessage(str.substring(0, str.indexOf(0)));
  63. break;
  64. case ChatParam.FULL:
  65. System.out.println("現在人数制限に達しています");
  66. flag = false;
  67. break;
  68. case ChatParam.JOIN:
  69. case ChatParam.MSG:
  70. str = new String(buf, 1, ChatParam.MSIZE - 1);
  71. mwin.printMessage(str.substring(0, str.indexOf(0)));
  72. }
  73. }
  74.  
  75. // 以下の部分はメッセージを送信する部分で、他の参加者からのメッセージ
  76. // を受信する部分とは並列にする必要があります。
  77. while (true) {
  78. send[0] = ChatParam.MSG;
  79. str = name + ":" + input.readLine() + "\0";
  80. mwin.printMessage(str);
  81. cbuf = str.getBytes();
  82. System.arraycopy(cbuf, 0, send, 1, (cbuf.length < ChatParam.MSIZE - 1)?cbuf.length:(ChatParam.MSIZE - 1));
  83.  
  84. /* send内のデータを送信 */
  85. }
  86.  
  87. /* 通信終了処理 */
  88.  
  89. } catch (Exception e) {
  90. System.out.println("connection error");
  91. System.exit(1);
  92. }
  93. }
  94. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:25: error: class ChatCl is public, should be declared in a file named ChatCl.java
public class ChatCl {
       ^
Main.java:27: error: cannot find symbol
    byte[] buf = new byte[ChatParam.MSIZE];
                          ^
  symbol:   variable ChatParam
  location: class ChatCl
Main.java:28: error: cannot find symbol
    byte[] send = new byte[ChatParam.MSIZE];
                           ^
  symbol:   variable ChatParam
  location: class ChatCl
Main.java:48: error: cannot find symbol
      send[0] = ChatParam.JOIN;
                ^
  symbol:   variable ChatParam
  location: class ChatCl
Main.java:50: error: cannot find symbol
      System.arraycopy(cbuf, 0, send, 1, (cbuf.length < ChatParam.NSIZE)?cbuf.length:ChatParam.NSIZE);
                                                        ^
  symbol:   variable ChatParam
  location: class ChatCl
Main.java:50: error: cannot find symbol
      System.arraycopy(cbuf, 0, send, 1, (cbuf.length < ChatParam.NSIZE)?cbuf.length:ChatParam.NSIZE);
                                                                                     ^
  symbol:   variable ChatParam
  location: class ChatCl
Main.java:61: error: cannot find symbol
	case ChatParam.LEAVE:
	     ^
  symbol:   variable ChatParam
  location: class ChatCl
Main.java:62: error: cannot find symbol
	  str = new String(buf, 1, ChatParam.MSIZE - 1);
	                           ^
  symbol:   variable ChatParam
  location: class ChatCl
Main.java:65: error: cannot find symbol
	case ChatParam.FULL:
	     ^
  symbol:   variable ChatParam
  location: class ChatCl
Main.java:69: error: cannot find symbol
	case ChatParam.JOIN:
	     ^
  symbol:   variable ChatParam
  location: class ChatCl
Main.java:70: error: cannot find symbol
	case ChatParam.MSG:
	     ^
  symbol:   variable ChatParam
  location: class ChatCl
Main.java:71: error: cannot find symbol
	  str = new String(buf, 1, ChatParam.MSIZE - 1);
	                           ^
  symbol:   variable ChatParam
  location: class ChatCl
Main.java:79: error: cannot find symbol
	send[0] = ChatParam.MSG;
	          ^
  symbol:   variable ChatParam
  location: class ChatCl
Main.java:83: error: cannot find symbol
	System.arraycopy(cbuf, 0, send, 1, (cbuf.length < ChatParam.MSIZE - 1)?cbuf.length:(ChatParam.MSIZE - 1));
	                                                  ^
  symbol:   variable ChatParam
  location: class ChatCl
Main.java:83: error: cannot find symbol
	System.arraycopy(cbuf, 0, send, 1, (cbuf.length < ChatParam.MSIZE - 1)?cbuf.length:(ChatParam.MSIZE - 1));
	                                                                                    ^
  symbol:   variable ChatParam
  location: class ChatCl
15 errors
stdout
Standard output is empty