Java Code Examples for javax.swing.JOptionPane.showInputDialog()

The following are Jave code examples for showing how to use showInputDialog() of the javax.swing.JOptionPane class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Dahlem_SER316   File: HTMLEditor.java   View Source Code Vote up 7 votes
public void takeScreenCap(ActionEvent e){
  	String inputValue = JOptionPane.showInputDialog("Choose a name for your screen capture.");
  	
  	SwingUtilities.getWindowAncestor(this).setVisible(false);
int option = JOptionPane.showConfirmDialog(null,
		"Click yes to capture screen, no to cancel.", "Take Capture", JOptionPane.YES_NO_OPTION);
if(option ==0)
{
	try{
  			Thread.sleep(1000);
  			
  		} catch(InterruptedException ex){
  			Thread.currentThread().interrupt();
  		}
	String toLink = Capture.doCapture(inputValue);
	SwingUtilities.getWindowAncestor(this).setVisible(true);
	
	
	toLink = "file:" + toLink;
	imageCaptureStart(toLink);
}
SwingUtilities.getWindowAncestor(this).setVisible(true);
  }
 
Example 2
Project: VASSAL-src   File: Deck.java   View Source Code Vote up 7 votes
public void promptForDragCount() {
  while (true) {
    final String s = JOptionPane.showInputDialog(
      Resources.getString("Deck.enter_the_number")); //$NON-NLS-1$
    if (s != null) {
      try {
        dragCount = Integer.parseInt(s);
        dragCount = Math.min(dragCount, getPieceCount());
        if (dragCount >= 0) break;
      }
      catch (NumberFormatException ex) {
        // Ignore if user doesn't enter a number
      }
    }
    else {
      break;
    }
  }
}
 
Example 3
Project: JavaClass   File: Interface.java   View Source Code Vote up 6 votes
public static void main(String[] args) {
	 Conjugaison InputConjugaison = new Conjugaison();
	    String result = JOptionPane.showInputDialog(null, "Veuillez entrer un verbe à l'infinitif se terminant par «er» :");
	    boolean resultat = InputConjugaison.estVerbeER(result);
	    if (resultat == true) {
	    		JOptionPane.showMessageDialog(null, InputConjugaison.afficheTable());
	    }
	    else {
	    		JOptionPane.showMessageDialog(null,"Vous n'avez pas fourni un verbe se terminant par «er».");
	    }

}
 
Example 4
Project: LivroJavaComoProgramar10Edicao   File: NameDialog.java   View Source Code Vote up 6 votes
public static void main(String[] args)
{
   // prompt user to enter name
   String name = JOptionPane.showInputDialog("What is your name?");
   
   // create the message
   String message =                                              
      String.format("Welcome, %s, to Java Programming!", name);

   // display the message to welcome the user by name 
   JOptionPane.showMessageDialog(null, message);
}
 
Example 5
Project: ramus   File: BranchView.java   View Source Code Vote up 6 votes
public void addChildBranch() {
    int row = table.getSelectedRow();
    if (row < 0)
        return;
    Node node = (Node) table.getPathForRow(row).getLastPathComponent();
    String message = GlobalResourcesManager
            .getString("BranchCreationWarning");
    if (node.branch.getChildren().size() > 0)
        message = GlobalResourcesManager
                .getString("BranchNodeCreationWarniong");
    if (JOptionPane.showConfirmDialog(framework.getMainFrame(), message,
            UIManager.getString("OptionPane.titleText"),
            JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) != JOptionPane.YES_OPTION)
        return;
    String s = JOptionPane.showInputDialog(framework.getMainFrame(),
            GlobalResourcesManager.getString("BranchCreationReason"),
            GlobalResourcesManager.getString("BranchCreationReason"),
            JOptionPane.QUESTION_MESSAGE);
    if (s == null)
        return;
    int type = node.branch.getType() - 1;
    if (node.branch.getChildren().size() > 0) {
        type = getMaxType(type, (Node) branchModel.getRoot());
    }
    engine.createBranch(node.branch.getBranchId(), s, type + 1, "core");
}
 
Example 6
Project: JavaGraph   File: LoadGrammarFromURLAction.java   View Source Code Vote up 6 votes
@Override
public void execute() {
    String input = JOptionPane.showInputDialog("Input Grammar URL:");
    if (input != null) {
        try {
            URL url = new URL(input);
            final SystemStore store = SystemStore.newStore(url);
            //                String startGraphName = url.getQuery();
            getActions().getLoadGrammarAction().load(store);
        } catch (MalformedURLException e) {
            showErrorDialog(e,
                String.format("Invalid URL '%s'", e.getMessage()));
        } catch (IOException exc) {
            showErrorDialog(exc, exc.getMessage());
        }
    }
}
 
Example 7
Project: komodoGUI   File: AddressBookPanel.java   View Source Code Vote up 6 votes
public void actionPerformed(ActionEvent e) {
    String name = (String) JOptionPane.showInputDialog(AddressBookPanel.this,
            "Please enter the name of the contact:",
            "Add new contact step 1",
            JOptionPane.PLAIN_MESSAGE,
            null,
            null,
            "");
    if (name == null || "".equals(name))
        return; // cancelled

    // TODO: check for dupes
    names.add(name);

    String address = (String) JOptionPane.showInputDialog(AddressBookPanel.this,
            "Pleae enter the t-address or z-address of "+name,
            "Add new contact step 2",
            JOptionPane.PLAIN_MESSAGE,
            null,
            null,
            "");
    if (address == null || "".equals(address))
        return; // cancelled
    entries.add(new AddressBookEntry(name,address));

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            table.invalidate();
            table.revalidate();
            table.repaint();

            saveEntriesToDisk();
        }
    });
}
 
Example 8
Project: 2D-Elliptic-Mesh-Generator   File: Axis.java   View Source Code Vote up 5 votes
/**
 * Opens a dialog window and asks the user for the name of this axis.
 * 
 * @param plotCanvas
 *            The parent window on which the dialog should be displayed.
 */
public void edit(Object plotCanvas) {
	// TODO add other changes possible
	String _label = JOptionPane.showInputDialog((PlotCanvas) plotCanvas,
			"Choose axis label", label);
	if (_label != null) {
		setLegend(_label);
	}
}
 
Example 9
Project: Dahlem_SER316   File: AppFrame.java   View Source Code Vote up 5 votes
public void actionPerformed(ActionEvent e){
	String inputValue = JOptionPane.showInputDialog("Choose a name for your screen capture.");
	
	AppFrame.this.setVisible(false);
	int option = JOptionPane.showConfirmDialog(null,
			"Click yes to capture screen, no to cancel.", "Take Capture", JOptionPane.YES_NO_OPTION);
	
	if(option ==0)
	{
		try{
   			Thread.sleep(1000);
   			
   		} catch(InterruptedException ex){
   			Thread.currentThread().interrupt();
   		}
		String toLink = Capture.doCapture(inputValue);
		AppFrame.this.setVisible(true);
		workPanel.selectPanel("NOTES");
		setEnabledEditorMenus(true);
		workPanel.dailyItemsPanel.editorPanel.newNoteCap();
		toLink = "file:" + toLink;
		editor.imageCaptureStart(toLink);
	}
	else
	{
		AppFrame.this.setVisible(true);
	}
}
 
Example 10
Project: estrutura-de-dados   File: Ex1.java   View Source Code Vote up 5 votes
public static void main(String[] args) {
    String p1, p2;
    String fruits[] = {"Maçã", "Banana", "Pêra", "Côco", "Maracujá", "Manga", "Melancia",
    "Melão", "Cereja", "Uva", "Caju", "Laranja", "Pêssego", "Jaca", "Romã", "Mexerica",
    "Tangerina", "Limão", "Abacate"};
    
    p1 = JOptionPane.showInputDialog(null, "1ª Palavra: ", "Palavra", JOptionPane.PLAIN_MESSAGE);
    p2 = JOptionPane.showInputDialog(null, "2ª Palavra: ", "Palavra", JOptionPane.PLAIN_MESSAGE);

    if (p1.compareToIgnoreCase(p2) > 0) {
        String tmp = p1;
        p1 = p2;
        p2 = tmp;
    }
    JOptionPane.showMessageDialog(null, String.format("1º Nome: %s\n2º Nome: %s", p1, p2),
            "Nomes", JOptionPane.PLAIN_MESSAGE);
    
    JOptionPane.showMessageDialog(null, "Primeira letra de " + p1 + " é " + primeiraLetra(p1),
            "Primeira Letra", JOptionPane.PLAIN_MESSAGE);
    JOptionPane.showMessageDialog(null, "Primeira letra de " + p2 + " é " + primeiraLetra(p2),
            "Primeira Letra", JOptionPane.PLAIN_MESSAGE);
    JOptionPane.showMessageDialog(null, "Quantidade de letras de " + p1 + " é " + quantasLetras(p1),
            "Quantas Letras", JOptionPane.PLAIN_MESSAGE);
    JOptionPane.showMessageDialog(null, "Quantidade de letras de " + p2 + " é " + quantasLetras(p2),
            "Quantas Letras", JOptionPane.PLAIN_MESSAGE);
    JOptionPane.showMessageDialog(null, "Última letra de " + p1 + " é " + ultimaLetra(p1),
            "Última Letra", JOptionPane.PLAIN_MESSAGE);
    JOptionPane.showMessageDialog(null, "Última letra de " + p2 + " é " + ultimaLetra(p2),
            "Última Letra", JOptionPane.PLAIN_MESSAGE);
    
    fruits = bubbleSort(fruits);
    
    for (String fruit : fruits)
        System.out.println(fruit);
}
 
Example 11
Project: cuttlefish   File: DBToolbar.java   View Source Code Vote up 5 votes
private void settingsButtonEvent() {
	String sleepTimeStr = (String)JOptionPane.showInputDialog(networkPanel, "Enter time between updates in milliseconds", "Time between updates", JOptionPane.QUESTION_MESSAGE, null, null, sleepTime);
	if(sleepTimeStr != null) {
		try {
			sleepTime = Long.parseLong(sleepTimeStr);
		} catch (NumberFormatException ex) {
			JOptionPane.showMessageDialog(networkPanel, "The value that you enter is not an integer", "Incorrect input", JOptionPane.WARNING_MESSAGE, null);
		}
	}
}
 
Example 12
Project: Examples   File: ConversaoStringNumero.java   View Source Code Vote up 5 votes
public static void main(String[] args) {
	
	/*
	 * Aqui será mostrado um pouco da utilização dos wrappers 
	 * Perceba que com eles consigo realizar conversões facilmente
	 */
	
	String resposta1 = JOptionPane.showInputDialog("Qual é sua nota 1 ?");
	String resposta2 = JOptionPane.showInputDialog("Qual é sua nota 2 ?");
	
	double nota1 = Double.parseDouble(resposta1);
	double nota2 = Double.parseDouble(resposta2);
	
	System.out.printf("Sua nota é %.2f", (nota1 + nota2) / 2);
}
 
Example 13
Project: JAddOn   File: JTreeUtils.java   View Source Code Vote up 5 votes
private static void addCategory(Component frame, String path, File folder_categories) {
    String input = JOptionPane.showInputDialog(frame, StaticStandard.getLang().getLang("new_category_name", "New category name") + ":", path);
    if (input != null && !input.isEmpty()) {
        input = input.replaceAll(File.separator + File.separator, ".");
        File folder = getFolderFromCategory(input, folder_categories);
        StaticStandard.log("Added category: \"" + input + "\"");
        folder.mkdirs();
    }
}
 
Example 14
Project: powertext   File: BasicEvents.java   View Source Code Vote up 5 votes
public static void Replace(){
    int sel = jTabbedPane1.getSelectedIndex();
    JTextArea textPane = (JTextArea) ((JScrollPane) ((JDesktopPane)jTabbedPane1.getComponentAt(sel)).getComponent(0)).getViewport().getComponent(0);
    try
{
	String replace = JOptionPane.showInputDialog(null, "Replace");
	textPane.replaceSelection(replace);
}catch(NumberFormatException nfe){}
}
 
Example 15
Project: OrthancAnonymization   File: DialogCellEditor.java   View Source Code Vote up 5 votes
@Override
public void actionPerformed(ActionEvent e) {
	if (EDIT.equals(e.getActionCommand())){
           newInput = JOptionPane.showInputDialog("Edit", oldValue);
           if (newInput == null){
               newInput = oldValue;
           }
           fireEditingStopped();
       }
}
 
Example 16
Project: Multithreaded-messenger   File: MainClient.java   View Source Code Vote up 5 votes
public static void main(String[] args) {

		String userName = JOptionPane.showInputDialog("Type in your guest-login user name: ");
		String IP = JOptionPane.showInputDialog("Type the ip to connect to: ");
		String hostString = JOptionPane.showInputDialog("Type the host to connect to: ");
		int host = Integer.valueOf(hostString);

		IClient client = new Client(IP, host);
		ClientGUI gui = new ClientGUI(client);
		gui.setUserName(userName);
		client.startClient();

	}
 
Example 17
Project: sota-sxt   File: TestFrame.java   View Source Code Vote up 5 votes
/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    //new Frame();
    String uno =  JOptionPane.showInputDialog("Dar primer número");
    double primero = Double.parseDouble(uno);
    
    String dos = JOptionPane.showInputDialog("Dar Segundo número");
    double segundo = Double.parseDouble(dos);
    
    double suma = primero + segundo;
    
    JOptionPane.showMessageDialog(null, "El resultado es: " + String.format("%.2f", suma));
}
 
Example 18
Project: zencash-swing-wallet-ui   File: AddressBookPanel.java   View Source Code Vote up 5 votes
public void actionPerformed(ActionEvent e) {
    String name = (String) JOptionPane.showInputDialog(AddressBookPanel.this,
            "Please enter the name of the contact:",
            "Add new contact step 1",
            JOptionPane.PLAIN_MESSAGE,
            null,
            null,
            "");
    if (name == null || "".equals(name))
        return; // cancelled

    // TODO: check for dupes
    names.add(name);
    
    String address = (String) JOptionPane.showInputDialog(AddressBookPanel.this,
            "Please enter the t-address or z-address of "+name,
            "Add new contact step 2",
            JOptionPane.PLAIN_MESSAGE,
            null,
            null,
            "");
    if (address == null || "".equals(address))
        return; // cancelled
    entries.add(new AddressBookEntry(name,address));
    
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            table.invalidate();
            table.revalidate();
            table.repaint();
        	
            saveEntriesToDisk();
        }
    });
}
 
Example 19
Project: Equella   File: GroupsTab.java   View Source Code Vote up 4 votes
@Override
public void actionPerformed(ActionEvent e)
{
	final GroupTreeNode parentGroup = getSelectedGroupNode();

	String prompt = null;
	while( Check.isEmpty(prompt) )
	{
		prompt = JOptionPane.showInputDialog(GroupsTab.this,
			CurrentLocale.get("com.tle.admin.usermanagement.internal.groupstabs.enter"),
			CurrentLocale.get("com.tle.admin.usermanagement.internal.groupstabs.new"),
			JOptionPane.QUESTION_MESSAGE);

		if( prompt == null )
		{
			return;
		}
		else if( prompt.trim().length() == 0 )
		{
			JOptionPane.showMessageDialog(GroupsTab.this,
				CurrentLocale.get("com.tle.admin.usermanagement.internal.groupstabs.notempty"));
		}
	}

	final String newGroupName = prompt;

	GlassSwingWorker<GroupTreeNode> worker = new GlassSwingWorker<GroupTreeNode>()
	{
		@Override
		public GroupTreeNode construct()
		{
			GroupTreeNode result = null;
			if( groupService.getByName(newGroupName) == null )
			{
				result = new GroupTreeNode();
				result.setName(newGroupName);

				String parentId = null;
				if( parentGroup != null )
				{
					parentId = parentGroup.getId();
				}

				result.setId(groupService.add(parentId, newGroupName));
			}
			return result;
		}

		@Override
		public void finished()
		{
			GroupTreeNode group = get();
			if( group == null )
			{
				JOptionPane.showMessageDialog(getComponent(),
					CurrentLocale.get("com.tle.admin.usermanagement.internal.groupstabs.inuse"));
			}
			else
			{
				GroupTreeNode parent = parentGroup;
				if( parent == null )
				{
					parent = (GroupTreeNode) model.getRoot();
				}

				model.insertNodeInto(group, parent, parent.getChildCount());
				tree.setSelectionPath(new TreePath(group.getPath()));
			}
		}

		@Override
		public void exception()
		{
			Driver.displayInformation(getComponent(),
				CurrentLocale.get("com.tle.admin.usermanagement.internal.groupstabs.errorcreating"));
			getException().printStackTrace();
		}
	};
	worker.setComponent(GroupsTab.this);
	worker.start();
}
 
Example 20
Project: appinventor-extensions   File: AIMerger.java   View Source Code Vote up 4 votes
private boolean alertToDuplicates() {
  for (String screen : mainProjectScreensCBL.getChecked()) {
    //Asks to rename Screen1 of second project if both Screen1s are checked.
    if (secondProjectScreensCBL.getChecked().contains("Screen1") && screen.equals("Screen1") &&
        newName == null) {
      JOptionPane.showMessageDialog(myCP, "Your project will not correctly merge with two " +
              "Screen1s checked." + "\n" + "Rename your second project's Screen1 to continue.",
          "Rename Screen1", JOptionPane.WARNING_MESSAGE);
      String path = "";
      String screenName = JOptionPane.showInputDialog(secondProjectDisplayP, "Rename",
          "Enter new name");
      // The screen's name must start with a letter and can only contain letters,
      // numbers and underscores.
      while (!Character.isLetter(screenName.charAt(0)) || !screenName.matches("^[a-zA-Z0-9_]*$") ||
          secondProjectScreensCBL.getChecked().contains(screenName) ||
          mainProjectScreensCBL.getChecked().contains(screenName) ||
          screenName.toLowerCase().equals("screen1")) {
        JOptionPane.showMessageDialog(myCP, "Screen names must start with a letter and "
                + "can contain only letters, numbers, " + "\n" + "and underscores, and cannot be "
                + "the same as another checked screen.", "File Name Error",
            JOptionPane.ERROR_MESSAGE);
        screenName = JOptionPane.showInputDialog(myCP, "Rename", "Enter new name");
      }
      for (AIScreen aiScreen : secondProject.getScreensList()) {
        if (aiScreen.getName().equals("Screen1")) {
          path += aiScreen.getPath();
        }
      }
      String newPath = path.substring(0, path.lastIndexOf('/') + 1) + screenName;
      oldName = pathNoExt(path);
      newName = newPath;
    }
    if (secondProjectScreensCBL.getChecked().contains(screen) && screen != "Check All" &&
        screen != "Screen1") {
      JOptionPane.showMessageDialog(myCP, "You cannot select two screens with the "
              + "same name. Please uncheck one of the screens and remerge.", "Duplicate Error",
          JOptionPane.ERROR_MESSAGE);
      return false;
    }
  }
  for (String asset : mainProjectAssetsCBL.getChecked()) {
    if (secondProjectAssetsCBL.getChecked().contains(asset) && asset != "Check All") {
      JOptionPane.showMessageDialog(myCP, "You cannot select two assets with the "
              + "same name. Please uncheck one of the assets and remerge.", "Duplicate Error",
          JOptionPane.ERROR_MESSAGE);
      return false;
    }
  }
  return true;
}