コード例 #1
0
  public void sendMessage() {
    if (client == null) {
      connect();
      return;
    }
    String toSomebody = combobox.getSelectedItem().toString();
    short channelType = 1;
    String status = "";
    if (checkbox.isSelected()) {
      status = "Secret";
    }
    String action = actionlist.getSelectedItem().toString();

    String message = clientMessage.getText();
    message = action + message;
    switch (toSomebody) {
      case "all":
        channelType = 2;
        break;
      default:
        message = status + message;
        break;
    }
    try {
      ChatMessage chat = new ChatMessage(channelType, message, userName, toSomebody);
      client.write(chat);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
コード例 #2
0
 public void disConnect() {
   loginButton.setEnabled(true);
   userButton.setEnabled(true);
   connectButton.setEnabled(true);
   logoffButton.setEnabled(false);
   clientMessage.setEnabled(false);
   try {
     client.destory();
     messageShow.append("Has been disconnected from the server\n");
     type = 0;
   } catch (Exception e) {
     e.printStackTrace();
   }
 }