示例#1
0
 // 写一个方法,让它显示消息
 public void show_message(MessageShare message_from_server) {
   String chat_info =
       message_from_server.get_sender()
           + " 对 "
           + message_from_server.get_receiver()
           + " 说:"
           + message_from_server.get_content()
           + "\r\n";
   this.chat_history_text_area.append(chat_info);
 }
示例#2
0
 public void actionPerformed(ActionEvent ae) {
   // 如果用户点击了发送按钮
   if (ae.getSource() == send_button) {
     // 就将发送者、接受者的信息以及聊天消息封装成数据包一并发送给服务器
     MessageShare message_to_server = new MessageShare();
     message_to_server.set_message_type(MessageType.is_chat_content);
     message_to_server.set_sender(this.user);
     message_to_server.set_receiver(this.friend);
     message_to_server.set_content(input_text_field.getText());
     message_to_server.set_send_time(new java.util.Date().toString());
     // 将数据包发送给服务器
     try {
       ObjectOutputStream object_output_stream =
           new ObjectOutputStream(
               ManageClientToServerConnectionThread.get_lient_to_server_connectinon_thread(user)
                   .get_socket()
                   .getOutputStream());
       object_output_stream.writeObject(message_to_server);
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
 }