String hostName = JOptionPane.showInputDialog("New host name: "); if (hostName == null || hostName.length() == 0) return;
String hostName = null; while (true) { hostName = JOptionPane.showInputDialog("New host name: "); if (hostName == null || hostName.length() == 0) return; HostComponent[] hc = experiment.getHosts(); boolean isUnique = true; for (int i = 0; i < hc.length; i++) if (hostName.equals(hc[i].getShortName())) { isUnique = false; break; } if (isUnique) break; int ok = JOptionPane.showConfirmDialog(this, "Use an unique name", "Host Name Not Unique", JOptionPane.OK_CANCEL_OPTION, JOptionPane.ERROR_MESSAGE); if (ok != JOptionPane.OK_OPTION) return; }
  public void newHostMenuItem_actionPerformed(ActionEvent e) {    String hostName = JOptionPane.showInputDialog("New host name: ");    if (hostName == null || hostName.length() == 0)      return;    DefaultTreeModel model = (DefaultTreeModel)hostTree.getModel();    DefaultMutableTreeNode hostTreeRoot =       (DefaultMutableTreeNode)model.getRoot();    HostComponent hostComponent = experiment.addHost(hostName);    ConsoleTreeObject cto = new ConsoleTreeObject(hostComponent);    DefaultMutableTreeNode hostNode = new DefaultMutableTreeNode(cto);    model.insertNodeInto(hostNode,			 hostTreeRoot,			 hostTreeRoot.getChildCount());    hostTree.scrollPathToVisible(new TreePath(hostNode.getPath()));  }