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

The following examples show how to use javax.swing.JOptionPane#showInputDialog() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AddPageActionProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void actionPerformed(ActionEvent e) {
    try {
        final PageFlowController pfc = scene.getPageFlowView().getPageFlowController();
        
        final FileObject webFileObject = pfc.getWebFolder();
        
        String name = FileUtil.findFreeFileName(webFileObject, "page", "jsp");
        name = JOptionPane.showInputDialog("Select Page Name", name);
        
        createIndexJSP(webFileObject, name);
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
    
    //            }
}
 
Example 2
Source File: GotoVariationDialog.java    From FancyBing with GNU General Public License v3.0 6 votes vote down vote up
public static ConstNode show(Component parent, ConstGameTree tree,
                             ConstNode currentNode,
                             MessageDialogs messageDialogs)
{
    String variation = NodeUtil.getVariationString(currentNode);
    Object value =
        JOptionPane.showInputDialog(parent, i18n("LB_VARIATION"),
                                    i18n("TIT_INPUT"),
                                    JOptionPane.PLAIN_MESSAGE, null, null,
                                    variation);
    if (value == null || value.equals(""))
        return null;
    ConstNode root = tree.getRootConst();
    ConstNode node = NodeUtil.findByVariation(root, (String)value);
    if (node == null)
        messageDialogs.showError(parent, i18n("MSG_VARIATION_INVALID"),
                                 i18n("MSG_VARIATION_INVALID_2"),
                                 false);
    return node;
}
 
Example 3
Source File: CompileFromString.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Main entry point for program; ask user for expressions,
 * compile, evaluate, and print them.
 *
 * @param args ignored
 * @throws java.lang.Exception exceptions are ignored for brevity
 */
public static void main(String... args) throws Exception {
    // Get a compiler tool
    final JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    final List<String> compilerFlags = new ArrayList();
    compilerFlags.add("-Xlint:all"); // report all warnings
    compilerFlags.add("-g:none"); // don't generate debug info
    String expression = "System.getProperty(\"java.vendor\")";
    while (true) {
        expression = JOptionPane.showInputDialog("Please enter a Java expression",
                                                 expression);
        if (expression == null)
            return; // end program on "cancel"
        long time = System.currentTimeMillis();
        Object result = evalExpression(compiler, null, compilerFlags, expression);
        time = System.currentTimeMillis() - time;
        System.out.format("Elapsed time %dms %n", time);
        if (result == ERROR)
            System.out.format("Error compiling \"%s\"%n", expression);
        else
            System.out.format("%s => %s%n", expression, result);
    }
}
 
Example 4
Source File: EditorActions.java    From blog-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 
 */
public void actionPerformed(ActionEvent e)
{
	if (e.getSource() instanceof mxGraphComponent)
	{
		mxGraphComponent graphComponent = (mxGraphComponent) e
				.getSource();
		Object[] cells = graphComponent.getGraph().getSelectionCells();

		if (cells != null && cells.length > 0)
		{
			String warning = JOptionPane.showInputDialog(mxResources
					.get("enterWarningMessage"));

			for (int i = 0; i < cells.length; i++)
			{
				graphComponent.setCellWarning(cells[i], warning);
			}
		}
		else
		{
			JOptionPane.showMessageDialog(graphComponent,
					mxResources.get("noCellSelected"));
		}
	}
}
 
Example 5
Source File: PurchaseInfoTab.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Action to buy a certain number of items.
 */
@Override
public void actionPerformed(ActionEvent e)
{
	boolean sellAll = quantity == SELL_ALL_QUANTITY;
	int num = quantity;
	if (num == 0)
	{
		String selectedValue =
				JOptionPane.showInputDialog(
					null, LanguageBundle.getString("in_igBuyEnterQuantity"), //$NON-NLS-1$
					Constants.APPLICATION_NAME, JOptionPane.QUESTION_MESSAGE);
		if (selectedValue != null)
		{
			try
			{
				num = (int) Float.parseFloat(selectedValue);
			}
			catch (NumberFormatException ex)
			{
				//Ignored
			}
		}
	}
	if (num > 0 || sellAll)
	{
		for (EquipmentFacade equip : targets)
		{
			if (sellAll)
			{
				num = character.getPurchasedEquipment().getQuantity(equip);
			}
			character.removePurchasedEquipment(equip, num, false);
		}
		availableTable.refilter();
	}
}
 
Example 6
Source File: GerenciadorDeContasInterface.java    From dctb-utfpr-2018-1 with Apache License 2.0 5 votes vote down vote up
private static Integer lerOpcaoDoMenu(){
	String menu = "[-------- Menu ---------]";
	menu += "\n[1] - Criar Conta";
	menu += "\n[2] - Consultar Saldo";
	menu += "\n[3] - Consultar Agencia";
	menu += "\n[4] - Alterar Titular";
	menu += "\n[5] - Remover Conta";
	menu += "\n[6] - Listar Contas";
	menu += "\n[7] - Sair";
	menu += "\n[ ------------------------- ]";
	menu += "\nInforme sua opcao: ";
	String strOpcao = JOptionPane.showInputDialog(null,menu);
	return Integer.parseInt(strOpcao);
}
 
Example 7
Source File: RenameSessionAction.java    From bigtable-sql with Apache License 2.0 5 votes vote down vote up
/**
 * Method for renaming a session.
 */
public void actionPerformed(ActionEvent evt)
{
	setSession(_app.getSessionManager().getActiveSession());

     String newTitle = JOptionPane.showInputDialog(_app.getMainFrame(),
           s_stringMgr.getString("RenameSessionAction.label"),
           s_stringMgr.getString("RenameSessionAction.title"),
           JOptionPane.QUESTION_MESSAGE);

     
     if(null == newTitle)
     {
        // Dialog was canceled.
        return;
     }
     

     if(!_session.getActiveSessionWindow().equals(_app.getWindowManager().getAllFramesOfSession(_session.getIdentifier())[0])) 
	{
		_session.getActiveSessionWindow().setTitle(newTitle);
	}
	else
	{
		_session.setTitle(newTitle);
		updateGui();
	}
}
 
Example 8
Source File: BirdController.java    From JavaMainRepo with Apache License 2.0 5 votes vote down vote up
public void actionPerformed(ActionEvent e) {
	// new AddController(new AddFrame("Hummingbird"), true);

	String choice = JOptionPane.showInputDialog("Load animal or enter info? (load/enter)");

	if (choice.equals("load")) {
		Animal animal = null;
		try {
			animal = speciesFactory.getAnimal(Constants.Animals.Birds.Hummingbird);
		} catch (Exception e2) {
			e2.printStackTrace();
		}
		animalList.add(animal);
		try {
			animalRepo.save(animalList);
		} catch (FileNotFoundException | XMLStreamException e1) {
			e1.printStackTrace();
		}
	} else if (choice.equals("enter")) {
		new AddController(new AddFrame("Hummingbird"), true);
		/*
		 * 
		 */

	} else {
		JOptionPane.showMessageDialog(frame, "Invalid choice.", "Warning", JOptionPane.WARNING_MESSAGE);
	}
}
 
Example 9
Source File: GerenciadorDeContaInterface.java    From dctb-utfpr-2018-1 with Apache License 2.0 5 votes vote down vote up
private static Integer lerOpcaoDoMenu() {
    String menu = "[-------- Menu ---------]";
    menu += "\n[1] - Criar Conta";
    menu += "\n[2] - Consultar Saldo";
    menu += "\n[3] - Consultar Agencia";
    menu += "\n[4] - Alterar Titular";
    menu += "\n[5] - Remover Conta";
    menu += "\n[6] - Listar Contas";
    menu += "\n[7] - Sair";
    menu += "\n[ ------------------------- ]";
    menu += "\nInforme sua opcao: ";
    String strOpcao = JOptionPane.showInputDialog(null, menu);
    return Integer.parseInt(strOpcao);
}
 
Example 10
Source File: EditorActions.java    From blog-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 
 */
public void actionPerformed(ActionEvent e)
{
	if (e.getSource() instanceof mxGraphComponent)
	{
		mxGraphComponent graphComponent = (mxGraphComponent) e
				.getSource();
		double scale = this.scale;

		if (scale == 0)
		{
			String value = (String) JOptionPane.showInputDialog(
					graphComponent, mxResources.get("value"),
					mxResources.get("scale") + " (%)",
					JOptionPane.PLAIN_MESSAGE, null, null, "");

			if (value != null)
			{
				scale = Double.parseDouble(value.replace("%", "")) / 100;
			}
		}

		if (scale > 0)
		{
			graphComponent.zoomTo(scale, graphComponent.isCenterZoom());
		}
	}
}
 
Example 11
Source File: Main.java    From dctb-utfpr-2018-1 with Apache License 2.0 5 votes vote down vote up
private static Integer lerOpcaoDoMenu() {
    String menu = "[-------- Menu ---------]";
    menu += "\n[1] - Criar Conta";
    menu += "\n[2] - Consultar Saldo";
    menu += "\n[3] - Consultar Agencia";
    menu += "\n[4] - Alterar Titular";
    menu += "\n[5] - Remover Conta";
    menu += "\n[6] - Listar Contas";
    menu += "\n[7] - Sair";
    menu += "\n[ ------------------------- ]";
    menu += "\nInforme sua opcao: ";
    String strOpcao = JOptionPane.showInputDialog(null, menu);
    return Integer.parseInt(strOpcao);
}
 
Example 12
Source File: BirdController.java    From JavaMainRepo with Apache License 2.0 5 votes vote down vote up
public void actionPerformed(ActionEvent e) {
	// new AddController(new AddFrame("Owl"), true);

	String choice = JOptionPane.showInputDialog("Load animal or enter info? (load/enter)");

	if (choice.equals("load")) {
		Animal animal = null;
		try {
			animal = speciesFactory.getAnimal(Constants.Animals.Birds.Owl);
		} catch (Exception e2) {
			e2.printStackTrace();
		}
		animalList.add(animal);
		try {
			animalRepo.save(animalList);
		} catch (FileNotFoundException | XMLStreamException e1) {
			e1.printStackTrace();
		}
	} else if (choice.equals("enter")) {
		new AddController(new AddFrame("Owl"), true);
		/*
		 * 
		 */

	} else {
		JOptionPane.showMessageDialog(frame, "Invalid choice.", "Warning", JOptionPane.WARNING_MESSAGE);
	}
}
 
Example 13
Source File: JCMService.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Update property values in the current props pane with those from the
 * selected configuration.
 */
void copyConfiguration()
{
  try {
    final Set<ConfigurationAlternative> cfgAlternatives =
      targetPanel.getAlternatives();

    final ConfigurationAlternative selectedValue =
      (ConfigurationAlternative) JOptionPane
          .showInputDialog(null, "Choose configuration to copy from",
                           "Select original to copy form",
                           JOptionPane.INFORMATION_MESSAGE, null,
                           cfgAlternatives.toArray(), cfgAlternatives
                               .iterator().next());
    if (selectedValue != null) {
      // If no cfg present in the selected alternative use the default (call
      // setProps with an empty dictionary)
      final Dictionary<String, Object> newProps =
        selectedValue.cfg != null
          ? selectedValue.cfg.getProperties()
          : new Hashtable<String, Object>();
      propPanel.setProps(newProps);
    }
  } catch (final Exception e) {
    final String msg = "Copy configuration values failed, " + e.getMessage();
    Activator.log.error(msg, e);
    showError(this, msg, e);
  }
}
 
Example 14
Source File: PositionClient.java    From kryonet with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public String inputName () {
	String input = (String)JOptionPane.showInputDialog(null, "Name:", "Connect to server", JOptionPane.QUESTION_MESSAGE,
		null, null, "Test");
	if (input == null || input.trim().length() == 0) System.exit(1);
	return input.trim();
}
 
Example 15
Source File: LHPNEditor.java    From iBioSim with Apache License 2.0 4 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
	dirty = true;
	Object o = e.getSource();
	if (o instanceof Runnable) {
		((Runnable) o).run();
	} else if (e.getSource() == abstButton) {
		String[] boolVars = lhpnFile.getBooleanVars();
		String[] contVars = lhpnFile.getContVars();
		String[] intVars = lhpnFile.getIntVars();
		String[] variables = new String[boolVars.length + contVars.length
				+ intVars.length];
		int k = 0;
		for (int j = 0; j < contVars.length; j++) {
			variables[k] = contVars[j];
			k++;
		}
		for (int j = 0; j < intVars.length; j++) {
			variables[k] = intVars[j];
			k++;
		}
		for (int j = 0; j < boolVars.length; j++) {
			variables[k] = boolVars[j];
			k++;
		}
		String abstFilename = JOptionPane.showInputDialog(this,
				"Please enter the file name for the abstracted LPN.",
				"Enter Filename", JOptionPane.PLAIN_MESSAGE);
		if (abstFilename != null) {
			if (!abstFilename.endsWith(".lpn"))
				abstFilename = abstFilename + ".lpn";
			String[] options = { "Ok", "Cancel" };
			JPanel panel = new JPanel();
			panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
			JCheckBox[] list = new JCheckBox[variables.length];
			ArrayList<String> tempVars = new ArrayList<String>();
			for (int i = 0; i < variables.length; i++) {
				JCheckBox temp = new JCheckBox(variables[i]);
				panel.add(temp);
				list[i] = temp;
			}
			int value = JOptionPane.showOptionDialog(Gui.frame, panel,
					"Variable Assignment Editor",
					JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE,
					null, options, options[0]);
			if (value == JOptionPane.YES_OPTION) {
				for (int i = 0; i < list.length; i++) {
					if (list[i].isSelected()) {
						tempVars.add(variables[i]);
					}
				}
				String[] vars = new String[tempVars.size()];
				for (int i = 0; i < tempVars.size(); i++) {
					vars[i] = tempVars.get(i);
				}
			}
		}
	}
}
 
Example 16
Source File: PortMapperApp.java    From portmapper with GNU General Public License v3.0 4 votes vote down vote up
public void connectRouter() throws RouterException {
    if (this.router != null) {
        logger.warn("Already connected to router. Cannot create a second connection.");
        return;
    }

    final AbstractRouterFactory routerFactory;
    try {
        routerFactory = createRouterFactory();
    } catch (final RouterException e) {
        logger.error("Could not create router factory: {}", e.getMessage(), e);
        return;
    }
    logger.info("Searching for routers...");

    final Collection<IRouter> foundRouters = routerFactory.findRouters();

    // No routers found
    if (foundRouters == null || foundRouters.isEmpty()) {
        throw new RouterException("Did not find a router");
    }

    // One router found: use it.
    if (foundRouters.size() == 1) {
        router = foundRouters.iterator().next();
        logger.info("Connected to router '{}'", router.getName());
        this.getView().fireConnectionStateChange();
        return;
    }

    // More than one router found: ask user.
    logger.info("Found more than one router (count: {}): ask user.", foundRouters.size());

    final ResourceMap resourceMap = getResourceMap();
    final IRouter selectedRouter = (IRouter) JOptionPane.showInputDialog(this.getView().getFrame(),
            resourceMap.getString("messages.select_router.message"),
            resourceMap.getString("messages.select_router.title"), JOptionPane.QUESTION_MESSAGE, null,
            foundRouters.toArray(), null);

    if (selectedRouter == null) {
        logger.info("No router selected.");
        return;
    }

    this.router = selectedRouter;
    this.getView().fireConnectionStateChange();
}
 
Example 17
Source File: GerenciadorDeContaInterface.java    From dctb-utfpr-2018-1 with Apache License 2.0 4 votes vote down vote up
private static Integer solicitarNumeroDaConta() {
    String strNumero = JOptionPane.showInputDialog(null, "Numero da Conta: ");

    return Integer.parseInt(strNumero);
}
 
Example 18
Source File: GuiUtils.java    From IrScrutinizer with GNU General Public License v3.0 4 votes vote down vote up
public String getInput(String message, String title, String defaultAnswer) {
    return (String) JOptionPane.showInputDialog(frame, message, title, JOptionPane.QUESTION_MESSAGE, null, null, defaultAnswer);
}
 
Example 19
Source File: RenameInOverviewFromTreeAction.java    From CQL with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Called when clicked upon, will rename an article.
 *
 * @param e The action event
 */
@Override
public void actionPerformed(ActionEvent e) {
	// If there is nothing seleceted then just do nothing
	if (_theFrame.getInfoTreeUI().getInfoTree().isSelectionEmpty()) {
		System.err.println("'OK'");

		return;
	}

	// Get currently selected object
	DefaultMutableTreeNode curSelected = (DefaultMutableTreeNode) _theFrame.getInfoTreeUI().getInfoTree()
			.getSelectionPath().getLastPathComponent();
	OverviewVertex nodeToRename;
	String originalName = "";

	// Check what is currently selected
	if (curSelected.getUserObject() instanceof SketchNode) {
		nodeToRename = (SketchNode) curSelected.getUserObject();
	} else if (curSelected.getUserObject() instanceof ViewNode) {
		nodeToRename = (ViewNode) curSelected.getUserObject();
	} else {
		return;
	}

	originalName = nodeToRename.getName();

	String s = (String) JOptionPane.showInputDialog(_theFrame, "New name:", "Rename", JOptionPane.QUESTION_MESSAGE,
			null, null, originalName);

	if (s != null) {
		s = s.trim();

		if (s.equals("")) {
			JOptionPane.showMessageDialog(_theFrame, "Entity name is empty", "Error", JOptionPane.ERROR_MESSAGE);
		} else if (_theFrame.getOverview().isNameUsed(s)) {
			JOptionPane.showMessageDialog(_theFrame, "Entity name is already in use", "Error",
					JOptionPane.ERROR_MESSAGE);
		} else {
			nodeToRename.setName(s);
			_theFrame.getInfoTreeUI().refreshTree();
			_theFrame.getOverview().getGraphLayoutCache().reload();
			_theFrame.getOverview().repaint();

			if (nodeToRename instanceof SketchNode) {
				((SketchNode) nodeToRename).getFrame().getMModel().setDirty();
			} else if (nodeToRename instanceof ViewNode) {
				((ViewNode) nodeToRename).getFrame().getMModel().setDirty();
			}
		}
	}

	_theFrame.getOverview().clearSelection();
}
 
Example 20
Source File: Main.java    From dctb-utfpr-2018-1 with Apache License 2.0 4 votes vote down vote up
private static String solicitarNomeDoTitular(){
	String nome = JOptionPane.showInputDialog(null, "Nome do titular: ");
	return nome;
}