private boolean validateServer() {
   String server = serverBox.getText();
   if (server.isEmpty()) {
     JOptionPane.showMessageDialog(null, "Please insert server id");
     return false;
   }
   if (Integer.parseInt(server) < 1 || Integer.parseInt(server) > mServerCount) {
     JOptionPane.showMessageDialog(null, "Server is not in range");
     return false;
   }
   return true;
 }
 private boolean validateKey() {
   String key = keyBox.getText();
   if (key.isEmpty()) {
     JOptionPane.showMessageDialog(null, "Please insert key");
     return false;
   }
   if (Integer.parseInt(key) < 1 || Integer.parseInt(key) > mServerCount * MaxSize) {
     JOptionPane.showMessageDialog(null, "Key is not in range");
     return false;
   }
   return true;
 }
 public void actionPerformed(ActionEvent e) {
   if (JOptionPane.showConfirmDialog(
           null,
           "Are you sure to purge distributed hash table?",
           "Purge",
           JOptionPane.YES_NO_OPTION)
       == JOptionPane.YES_OPTION) {
     sendPurgeRequest();
   }
 }
 public void actionPerformed(ActionEvent e) {
   String action = actionGroup.getSelection().getActionCommand();
   String key = keyBox.getText();
   String value = valueBox.getText();
   String server = serverBox.getText();
   if (action == "insert") {
     if (!validateKey()) {
       return;
     } else if (value.isEmpty()) {
       JOptionPane.showMessageDialog(null, "Please insert value");
       return;
     }
     if (!validateServer()) {
       return;
     }
     sendInsertRequest(Integer.parseInt(key), value, Integer.parseInt(server));
   } else if (action == "lookup") {
     if (!validateKey()) {
       return;
     }
     if (!validateServer()) {
       return;
     }
     sendLookupRequest(Integer.parseInt(key), Integer.parseInt(server));
   } else if (action == "delete") {
     if (!validateKey()) {
       return;
     }
     if (!validateServer()) {
       return;
     }
     sendDeleteRequest(Integer.parseInt(key), Integer.parseInt(server));
   } else if (action == "count") {
     if (!validateServer()) {
       return;
     }
     sendCountRequest(Integer.parseInt(server));
   }
 }