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

The following are Jave code examples for showing how to use showOptionDialog() 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: appinventor-extensions   File: AIMerger.java   View Source Code Vote up 7 votes
private void closeApplication() {
  int response = JOptionPane.showOptionDialog(myCP, "Exit AIMerger?", "Exit",
      JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null,
      JOptionPane.YES_OPTION);
  switch (response) {
    default:
      // This should never happen
      throw new IllegalArgumentException("not an option");
    case JOptionPane.CLOSED_OPTION:
    case JOptionPane.CANCEL_OPTION:
      offerNewMerge();
      break;
    case JOptionPane.OK_OPTION:
      System.exit(0);
      break;
  }
}
 
Example 2
Project: student_database   File: AddPanel.java   View Source Code Vote up 7 votes
private void errorDialogue(String messageString, int whichField) {
    Object[] message = {messageString};
    Object[] options = {"OK"};
    int n = JOptionPane.showOptionDialog(new JFrame(),
            message, "Alert!",
            JOptionPane.ERROR_MESSAGE, JOptionPane.ERROR_MESSAGE, null,
            options, options[0]);
    if(JOptionPane.ERROR_MESSAGE == n && whichField == 0){
        this.addStudentFullName.setText("");
    } else if(n == JOptionPane.ERROR_MESSAGE && whichField == 1){
        this.addStudentID.setText("171-15-XXXX");
    } else if(n == JOptionPane.ERROR_MESSAGE && whichField == 2){
        this.addFathersNameField.setText("");
    } else if(n == JOptionPane.ERROR_MESSAGE && whichField == 3){
        this.addMothersNameField.setText("");
    } else if(n == JOptionPane.ERROR_MESSAGE && whichField == 4){
        displayUpdateStudentPanel(true, false);
    } else if(n == JOptionPane.ERROR_MESSAGE && whichField == 5){
        panelVisiblity(true, false, false, false);
    } else if(n == JOptionPane.ERROR_MESSAGE && whichField == 6){
        loginVisiblity(true, false);
    } else {
        //DO NOTHING JUST DISPLAY MESSAGE
    }
}
 
Example 3
Project: appinventor-extensions   File: AIMerger.java   View Source Code Vote up 6 votes
private void offerNewMerge() {
  int response = JOptionPane.showOptionDialog(myCP, "Projects Successfully Merged. "
      + "Would you like to merge more projects?", "Projects Merged", JOptionPane.YES_NO_OPTION,
      JOptionPane.INFORMATION_MESSAGE, null, null, JOptionPane.YES_OPTION);
  switch (response) {
    default:
      // This should never happen
      throw new IllegalArgumentException("not an option");
    case JOptionPane.CLOSED_OPTION:
    case JOptionPane.NO_OPTION:
      closeApplication();
      break;
    case JOptionPane.YES_OPTION:
      offerToMergeToNewProject();
      break;
  }
}
 
Example 4
Project: xdman   File: XDMMainWindow.java   View Source Code Vote up 6 votes
int getDupAction(String url) {
	JTextField txt = new JTextField(url, 30);
	String lbl = StringResource.getString("DUP_TXT");
	JComboBox choice = new JComboBox(new String[] { StringResource.getString("DUP_OP1"),
			StringResource.getString("DUP_OP2"), StringResource.getString("DUP_OP3") });
	JCheckBox chk = new JCheckBox(StringResource.getString("DUP_CHK"));
	int ret = JOptionPane.showOptionDialog(null, new Object[] { txt, lbl, choice, chk },
			StringResource.getString("DUP_TITLE"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null,
			null, null);
	if (ret == JOptionPane.OK_OPTION) {
		int index = choice.getSelectedIndex();
		if (chk.isSelected()) {
			config.duplicateLinkAction = index;
		}
		return index;
	}
	return -1;
}
 
Example 5
Project: BlackjackProjectJava   File: BlackjackProjectDriver.java   View Source Code Vote up 6 votes
public Card checkCard(Card card)
{
    if(card.getPointValue() == 1)
    {
        Object[] options =
        {
            "1 Point!",
            "11 Points!"
        };
        int ask = JOptionPane.showOptionDialog(rootPane,
          "You drew an Ace. Would you like it to be worth 1 or 11 points?",
          "Blackjack Game",
          JOptionPane.YES_NO_OPTION,
          JOptionPane.QUESTION_MESSAGE,
          null, options, options[0]);
        if(ask == 1)
            card.setPointValue(11);
        else
            card.setPointValue(1);
    }
    return card;
}
 
Example 6
Project: parabuild-ci   File: CommonSwing.java   View Source Code Vote up 6 votes
public static void errorMessage(Exception exceptionMsg, boolean quiet) {

        /**
         * Display Jpanel Error messages any SQL Errors. Overloads
         * errorMessage(String e)
         */
        Object[] options = { "OK", };

        JOptionPane.showOptionDialog(null, exceptionMsg, messagerHeader,
                                     JOptionPane.DEFAULT_OPTION,
                                     JOptionPane.ERROR_MESSAGE, null,
                                     options, options[0]);

        if (!quiet) {
            exceptionMsg.printStackTrace();
        }

        // DatabaseManagerSwing.StatusMessage(READY_STATUS);
    }
 
Example 7
Project: openjdk-jdk10   File: ExceptionSafePlugin.java   View Source Code Vote up 5 votes
private void showExceptionDialog(Exception e) {
    Object[] buttonTexts = {
        Messages.PLUGIN_EXCEPTION_DIALOG_BUTTON_OK,
        Messages.PLUGIN_EXCEPTION_DIALOG_BUTTON_EXIT,
        Messages.PLUGIN_EXCEPTION_DIALOG_BUTTON_IGNORE
    };

    String message = String.format(
        Messages.PLUGIN_EXCEPTION_DIALOG_MESSAGE,
        plugin.getClass().getSimpleName(),
        String.valueOf(e.getMessage())
    );

    int buttonIndex = JOptionPane.showOptionDialog(
        null,
        message,
        Messages.PLUGIN_EXCEPTION_DIALOG_TITLE,
        JOptionPane.YES_NO_CANCEL_OPTION,
        JOptionPane.ERROR_MESSAGE,
        null,
        buttonTexts,
        buttonTexts[0]
    );

    if (buttonIndex == 1) {
        System.exit(0);
    }
    ignoreExceptions = buttonIndex == 2;
}
 
Example 8
Project: AWGW   File: WorldFrame.java   View Source Code Vote up 5 votes
public void showDirectionsPopup() {
    ImageIcon ico = MenuMaker.get16xIcon(getClass().getClassLoader().getResource("32x/intel.png"));
    JButton[] options = new JButton[2];
    JButton nahButton = GUIController.generateOkayButton(null, display);
    nahButton.setText("I already know how to play");
    nahButton.setFocusable(false);
    options[0] = nahButton;
    JButton openLink = new JButton(
            "<html> <a href=\"\">https://en.wikipedia.org/wiki/Advance_Wars#Gameplay</a></html>");
    openLink.setIcon(ico);
    openLink.setFocusable(false);
    openLink.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (Desktop.isDesktopSupported()) {
                try {
                    Desktop.getDesktop().browse(new URI("https://en.wikipedia.org/wiki/Advance_Wars#Gameplay"));
                } catch (Exception exept) {
                    /* TODO: error handling */
                }

            } else {
	/* TODO: error handling */
            }

        }
    });
    options[1] = openLink;

    JOptionPane.showOptionDialog(this, "Please see the following page (click link below):\n" + ""
            + "\nI added quite a few more Units to the game." + "\nCommanding Officers are not yet implemented\n"
            + "\nIn short, click a unit you wish to move, where to move, and what to do"
            + "\n To win, capture the enemy HQ or destroy all enemy units!", "How to Play", 0, 0, ico, options, 0);

}
 
Example 9
Project: ViolenciaContraMulher   File: TelaCadastroUsuario.java   View Source Code Vote up 5 votes
private void btnSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSairActionPerformed
    Object[] options = {"Sim", "Não"};
    if (JOptionPane.showOptionDialog(null, "Deseja mesmo sair da aplicação?", "Cadastro de Usuários",
            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]) == JOptionPane.YES_OPTION) {
        System.exit(0);
    }
}
 
Example 10
Project: The-Mysterious-Mind-Of-Jack   File: Main.java   View Source Code Vote up 5 votes
@Override
public void windowClosing(WindowEvent arg0) {
	Player player = StateHandler.player;
	if (player != null && StateHandler.getState().equals(States.GAME) || StateHandler.getState().equals(States.PAUSE)) {
		if (StateHandler.getState().equals(States.GAME)) StateHandler.pause();
		int confirm = JOptionPane.showOptionDialog(null, "Would you like to save?", "Exit Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
		if (confirm == 0) {
			DataHandler.savePlayer(player);
		}
	}
	System.exit(0);
}
 
Example 11
Project: xdman   File: ConfigDialog.java   View Source Code Vote up 5 votes
Credential getCredential(String shost, String suser, String spass) {
	JTextField host = new JTextField(shost);
	JTextField user = new JTextField(suser);
	JPasswordField pass = new JPasswordField(spass);
	Object[] obj = new Object[6];
	obj[0] = getString("HOST");
	obj[1] = host;
	obj[2] = getString("USER_NAME");
	obj[3] = user;
	obj[4] = getString("PASSWORD");
	obj[5] = pass;

	while (JOptionPane.showOptionDialog(null, obj, getString("LBL_CR"),
			JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE,
			null, null, null) == JOptionPane.OK_OPTION) {
		if (host.getText() == null || host.getText().length() < 1) {
			JOptionPane.showMessageDialog(null, getString("LBL_HOST"));
			continue;
		}
		if (user.getText() == null || user.getText().length() < 1) {
			JOptionPane.showMessageDialog(null, getString("LBL_USER"));
			continue;
		}

		Credential c = new Credential();
		c.host = host.getText();
		c.user = user.getText();
		c.pass = pass.getPassword().length > 0 ? new String(pass
				.getPassword()) : null;
		return c;
	}
	return null;
}
 
Example 12
Project: ViolenciaContraMulher   File: ConsultarFichaNotificacaoHospital.java   View Source Code Vote up 5 votes
private void btnExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExcluirActionPerformed
    int linha = tabelaHospital.getSelectedRow();
    Object[] options = {"Sim", "Não"};
    if (linha == -1) {
        JOptionPane.showMessageDialog(rootPane, "Selecione uma linha!");
    } else if (JOptionPane.showOptionDialog(null, "Deseja mesmo excluir esse Cadastro?", "Excluir Cadastro",
            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]) == JOptionPane.YES_OPTION) {
        hospital = hospitalDAO.pesquisarHospitalPorID((int) tabelaHospital.getValueAt(linha, 0));
        hospitalDAO.deletar(hospital);
        JOptionPane.showMessageDialog(null, "Cadastro excluído com sucesso");
        atualizarTabela();
    }

}
 
Example 13
Project: 20170612-NotaFIscalEletronica   File: FrameCadastroNf.java   View Source Code Vote up 5 votes
private void actionRemoverItem(){
		
		remItem = new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				
				
				if (tabelaItem.getSelectedRow()==-1){
					JOptionPane.showMessageDialog(null, "Selecione o registro a ser apagado","Alerta", JOptionPane.PLAIN_MESSAGE);
					return;
				}
				Object[] options = {"Sim", "Não"};
				int n = JOptionPane.showOptionDialog(null, "Deseja realmente apagar o registro: "+tabelaItem.getSelectedRow(), "Alerta", JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE, null, options,options[0] );
				
				if (n == 1){
					return;
				}
				
//				Realiza o calculo dos campos valorTotal e quantidade
				int quant = -1 + Integer.parseInt(quantidadeItens.getText());
				quantidadeItens.setText("" + quant);
				String j =""+tabelaItem.getValueAt(tabelaItem.getSelectedRow(), 4);
				double valorF = - Double.parseDouble(j) + Double.parseDouble(valorTotal.getText());
				valorTotal.setText("" + valorF);
				
//				Somente após o calculo é removida a linha da tabela
				modelItem.removeRow(tabelaItem.getSelectedRow());
			}
		};
	}
 
Example 14
Project: EditCalculateAndChart   File: New_Action.java   View Source Code Vote up 5 votes
public void actionPerformed(ActionEvent e) {
    String currentFileName = TEdit.getCurrentFileName();
   
    Object[] options = {"Cancel",
                "No",
                "Yes"};
    int n = JOptionPane.showOptionDialog(TEdit.getFrame(),
            "Would you like to save "+ currentFileName +" ?",
             "Save",
             JOptionPane.YES_NO_CANCEL_OPTION,
             JOptionPane.QUESTION_MESSAGE,
             null,
             options,
             options[0]);
    if(n == 0)
         return;
               if(n==2){
                   if(currentFileName.contentEquals("Untitled"))
                       TEdit.saveFileAs();
                   else
                    TEdit.saveFile(currentFileName);
               }
               if(n==1){
                    TEdit.updateTextArea("","Untitled");
                    TEdit.setEnabled("SaveAs",true);
               }
    //displayResult("Action for first button/menu item", e);
    
}
 
Example 15
Project: Bachelor-Thesis   File: DTNSimGUI.java   View Source Code Vote up 5 votes
/**
 * Processes assertion errors by showing a warning dialog to the user
 * and pausing the simulation (if it's running)
 * @param e The error that was thrown
 */
private void processAssertionError(AssertionError e) {
	String title = e.getClass().getSimpleName() + " (simulation paused)";
	String msg = e.getMessage();
	String txt = (msg != null ? msg : "") + " at simtime " + 
		SimClock.getIntTime() +	"\n\ncaught at:\n" + 
		e.getStackTrace()[0].toString() + 
		"\nNote that the simulation might be in inconsistent state, "+ 
		"continue only with caution.\n\n Show rest of the stack trace?";
	// rest of the update cycle that caused the exception is skipped
	// so the user is warned about the consequences

	
	if (guiControls != null) {
		guiControls.setPaused(true);
	}
	
	int selection = JOptionPane.showOptionDialog(getParentFrame(), txt,
			title, JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE,
			null, null, null);
	
	if (selection == 0) {
		txt = "";
		for (StackTraceElement trace : e.getStackTrace()) {
			txt += trace.toString()+"\n";
		}
		JOptionPane.showMessageDialog(getParentFrame(), txt,
			"stack trace", JOptionPane.INFORMATION_MESSAGE);
	}
}
 
Example 16
Project: ViolenciaContraMulher   File: ConsultarCadastro.java   View Source Code Vote up 5 votes
private void btnExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExcluirActionPerformed
    int linha = tabelaUsuarios.getSelectedRow();
    Object[] options = {"Sim", "Não"};
    if (linha == -1) {
        JOptionPane.showMessageDialog(rootPane, "Selecione uma linha!");
    } else if (JOptionPane.showOptionDialog(null, "Deseja mesmo excluir esse Usuário?", "Consultar Usuário",
            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]) == JOptionPane.YES_OPTION) {
        usuario = usuarioDAO.pesquisarUsuarioPorID((int) tabelaUsuarios.getValueAt(linha, 0));
        usuarioDAO.deletar(usuario);
        JOptionPane.showMessageDialog(null, "Usuário excluído com sucesso!");
        atualizarTabela();
    }


}
 
Example 17
Project: Equella   File: UserDetailsPanel.java   View Source Code Vote up 4 votes
public void loadUser(final TLEUser user)
{
	if( !changeDetector.hasDetectedChanges() )
	{
		loadDetails(user);
	}
	else
	{
		Object[] buttons = new Object[]{
				CurrentLocale.get("com.tle.admin.usermanagement.internal.userdetailspanel.save"), //$NON-NLS-1$
				CurrentLocale.get("com.tle.admin.usermanagement.internal.userdetailspanel.dontsave")}; //$NON-NLS-1$
		int results = JOptionPane.showOptionDialog(this,
				CurrentLocale.get("com.tle.admin.usermanagement.internal.userdetailspanel.confirm"), //$NON-NLS-1$
				CurrentLocale.get("com.tle.admin.usermanagement.internal.userdetailspanel.saveuser"), //$NON-NLS-1$
				JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, buttons, buttons[1]);

		if( results == JOptionPane.NO_OPTION )
		{
			loadDetails(user);
		}
		else if( results == JOptionPane.YES_OPTION )
		{
			new MyGlassSwingWorker()
			{
				@Override
				public void doStuff()
				{
					saveLoadedUser();
					JOptionPane.showMessageDialog(getComponent(),
							CurrentLocale.get("com.tle.admin.usermanagement.internal.userdetailspanel.saved")); //$NON-NLS-1$
				}

				@Override
				public void finished()
				{
					loadDetails(user);
				}
			}.start();
		}
	}
}
 
Example 18
Project: Equella   File: AbstractTreeEditor.java   View Source Code Vote up 4 votes
public void saveChanges(final Runnable actionAfterSave)
{
	if( currentEditor == null || !currentEditor.hasChanges() )
	{
		actionAfterSave.run();
		return;
	}

	String message = CurrentLocale.get("com.tle.admin.gui.common.tree.nodeeditor.saveconfirm");
	String[] buttons = {CurrentLocale.get("com.dytech.edge.admin.gui.save"),
			CurrentLocale.get("com.dytech.edge.admin.gui.dontsave"),
			CurrentLocale.get("com.dytech.edge.admin.gui.cancel")};
	final int confirm = JOptionPane.showOptionDialog(this, message,
		CurrentLocale.get("com.dytech.edge.admin.gui.savechanges"), JOptionPane.YES_NO_CANCEL_OPTION,
		JOptionPane.WARNING_MESSAGE, null, buttons, buttons[0]);

	if( confirm == JOptionPane.CANCEL_OPTION )
	{
		return;
	}
	else if( confirm == JOptionPane.NO_OPTION )
	{
		actionAfterSave.run();
		return;
	}

	// We must save then run the runnable
	GlassSwingWorker<?> worker = new GlassSwingWorker<Object>()
	{
		@Override
		public Object construct()
		{
			currentEditor.doSave();
			return null;
		}

		@Override
		public void finished()
		{
			actionAfterSave.run();
		}

		@Override
		public void exception()
		{
			JOptionPane.showMessageDialog(getComponent(),
				CurrentLocale.get("com.tle.admin.gui.common.tree.nodeeditor.saveerror"));
			getException().printStackTrace();
		}
	};
	worker.setComponent(this);
	worker.start();
}
 
Example 19
Project: osumer   File: BeatmapSearchPanel.java   View Source Code Vote up 4 votes
private ProgressDialog doUiLogin(Config config) {
    ProgressDialog pbd = new ProgressDialog();
    pbd.setTitle("osums Login Client");
    Thread th = new Thread() {
        public void run() {
            pbd.getProgressBar().setIndeterminate(true);
            pbd.getLabel().setText("Status: Getting configuration...");
            String user = config.getUser();
            String pass = config.getPass();

            if (user == null || user.isEmpty() || pass == null || pass.isEmpty()) {
                pbd.getLabel().setText("Status: Prompting username and password...");
                LoginPanel loginPanel = new LoginPanel();
                int option = JOptionPane.showOptionDialog(frame, loginPanel, "Login to osu!",
                        JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null,
                        JOptionPane.CANCEL_OPTION);

                if (option == JOptionPane.OK_OPTION) {
                    if (loginPanel.getUsername().isEmpty() || loginPanel.getPassword().isEmpty()) {
                        JOptionPane.showMessageDialog(frame, "Username or password cannot be empty.",
                                "Error", JOptionPane.ERROR_MESSAGE);
                        pbd.dispose();
                        return;
                    }

                    user = loginPanel.getUsername();
                    pass = loginPanel.getPassword();
                } else {
                    pbd.dispose();
                    return;
                }
            }

            pbd.getLabel().setText("Status: Logging in...");
            try {
                osums.login(user, pass);
            } catch (DebuggableException e) {
                e.printStackTrace();
                JOptionPane.showMessageDialog(frame, "Error logging in:\n" + e.getDump().getMessage(),
                        "Error", JOptionPane.ERROR_MESSAGE);
                pbd.dispose();
                return;
            }

            pbd.dispose();
        }
    };
    th.setDaemon(true);
    th.start();
    
    pbd.setLocationRelativeTo(BeatmapSearchPanel.this);
    pbd.setModal(true);
    pbd.setVisible(true);
    return pbd;
}
 
Example 20
Project: rlc-analyser   File: RLCContentPanel.java   View Source Code Vote up 2 votes
/**
 * This method creates an option dialog box to allow the user to select what
 * user would like to do after the export is completed successfully. If 1 is
 * returned then the created file should be opened for display.
 *
 * @return int representing the option selected by the user
 */
public int optionCSVRLCConsole() {
	final Object[] options = {"OK", "Open File"};
	return JOptionPane.showOptionDialog(this.mainContentPanel, "Successfully exported to CSV", "Export Successful",
	                                    JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]);
}