void jTextFieldSendMessages_keyPressed(KeyEvent e) {
   if (e.getKeyCode() == e.VK_DOWN) {
     String s = msgHistory.forward();
     if (s != null) {
       jTextFieldSendMessages.setText(s);
     }
   } else if (e.getKeyCode() == e.VK_UP) {
     String s = msgHistory.back();
     if (s != null) {
       jTextFieldSendMessages.setText(s);
     }
   } else if (e.getKeyChar() == '\n') {
     String body = jTextFieldSendMessages.getText();
     if (body.length() > 0) {
       if (body.charAt(body.length() - 1) == '\n') body = body.substring(0, body.length() - 1);
       String subject = jTextFieldSendSubject.getText();
       if (subject.length() > 0) {
         if (subject.charAt(subject.length() - 1) == '\n')
           subject = subject.substring(0, subject.length() - 1);
       }
       if (session != null && session.isConnected()) {
         session.postMessage(jTextFieldTargetUser.getText(), subject, body);
         displaySendMessage(subject, jTextFieldTargetUser.getText(), body, outgoingMsgAttrSet);
       }
       msgHistory.add(body);
       subjectHistory.add(subject);
       subjectHistory.reset();
       msgHistory.reset();
       jTextFieldSendMessages.setText("");
       jTextFieldSendSubject.setText("");
     }
   }
 }
 private void disconnect() {
   if (session != null && session.isConnected()) {
     session.disconnect();
   }
   jToggleButtonConnect.setSelected(false);
   jToggleButtonConnect.setText("Connect");
   jToggleButtonRegister.setSelected(false);
   onlineUsers.clear();
   jToggleButtonRegister.setText("Register");
 }
 private void register() {
   if (session != null && session.isConnected()) {
     onlineUsers.clear();
     // get the current list
     Message msg = session.sendMessage("", "list", "");
     System.out.println("LIST: " + msg.getBody());
     StringTokenizer st = new StringTokenizer(msg.getBody(), "\n");
     while (st.hasMoreTokens()) {
       onlineUsers.addElement(new HostItem(st.nextToken()));
     }
     session.postMessage("", "register", "");
   }
 }
  private void uneavesdrop() {
    if (session == null || !session.isConnected()) return;
    // get the list of selected hosts from the online list
    Object[] values = jListOnlineUsers.getSelectedValues();
    if (values == null) return;

    // iterate through the list of hosts
    for (int i = 0; i < values.length; i++) {
      // if a host is not being eavesdropped on, skip it
      HostItem hi = (HostItem) values[i];
      if (hi.eavesDroppingEnabled) {
        session.postMessage("", "uneavesdrop", hi.name);
      }
    }
  }
 private void handleRegister() {
   if (session == null || !session.isConnected()) {
     jToggleButtonRegister.setSelected(false);
     jMenuItemOptionsDeregister.setEnabled(false);
     jMenuItemOptionsRegister.setEnabled(true);
     return;
   }
   if (jToggleButtonRegister.isSelected() || jMenuItemOptionsRegister.isEnabled()) {
     register();
     jToggleButtonRegister.setText("Deregister");
     jMenuItemOptionsDeregister.setEnabled(true);
     jMenuItemOptionsRegister.setEnabled(false);
   } else {
     deregister();
     jToggleButtonRegister.setText("Register");
     jMenuItemOptionsDeregister.setEnabled(false);
     jMenuItemOptionsRegister.setEnabled(true);
   }
 }
 private void globalUneavesdrop() {
   if (session == null || !session.isConnected()) return;
   jMenuItemOptionsGlobalEavesdrop.setEnabled(true);
   jMenuItemOptionsGlobalUneavesdrop.setEnabled(false);
   session.postMessage("", "unglobaleavesdrop", "");
 }
 private void deregister() {
   onlineUsers.clear();
   if (session != null && session.isConnected()) {
     session.postMessage("", "deregister", "");
   }
 }