List of usage examples for javax.swing JOptionPane showOptionDialog
@SuppressWarnings("deprecation") public static int showOptionDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon, Object[] options, Object initialValue) throws HeadlessException
initialValue
parameter and the number of choices is determined by the optionType
parameter. From source file:JavaMail.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: try {/*from ww w .jav a 2s . com*/ String from = jTextField1.getText(); String to = jTextField2.getText(); String subject = jTextField3.getText(); String content = jTextArea1.getText(); Email email = new SimpleEmail(); String provi = prov.getSelectedItem().toString(); if (provi.equals("Gmail")) { email.setHostName("smtp.gmail.com"); email.setSmtpPort(465); serverlink = "smtp.gmail.com"; serverport = 465; } if (provi.equals("Outlook")) { email.setHostName("smtp-mail.outlook.com"); serverlink = "smtp-mail.outlook.com"; email.setSmtpPort(25); serverport = 25; } if (provi.equals("Yahoo")) { email.setHostName("smtp.mail.yahoo.com"); serverlink = "smtp.mail.yahoo.com"; email.setSmtpPort(465); serverport = 465; } System.out.println("Initializing email sending sequence"); System.out.println("Connecting to " + serverlink + " at port " + serverport); JPanel panel = new JPanel(); JLabel label = new JLabel( "Enter the password of your email ID to connect with your Email provider." + "\n"); JPasswordField pass = new JPasswordField(10); panel.add(label); panel.add(pass); String[] options = new String[] { "OK", "Cancel" }; int option = JOptionPane.showOptionDialog(null, panel, "Enter Email ID Password", JOptionPane.NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[1]); if (option == 0) // pressing OK button { char[] password = pass.getPassword(); emailpass = new String(password); } email.setAuthenticator(new DefaultAuthenticator(from, emailpass)); email.setSSLOnConnect(true); if (email.isSSLOnConnect() == true) { System.out.println("This server requires SSL/TLS authentication."); } email.setFrom(from); email.setSubject(subject); email.setMsg(content); email.addTo(to); email.send(); JOptionPane.showMessageDialog(null, "Message sent successfully."); } catch (Exception e) { e.printStackTrace(); } }
From source file:me.childintime.childintime.InitialSetup.java
/** * Show the confirmation dialog./* ww w .j a v a2 s .c om*/ * * @return True if the user agree'd, false if not. */ private boolean showConfirmationDialog() { // Create a list with the buttons to show in the option dialog List<String> buttons = new ArrayList<>(); buttons.add("Continue"); buttons.add("Quit"); // Reverse the button list if we're on a Mac OS X system if (Platform.isMacOsX()) Collections.reverse(buttons); // Show the option dialog final int option = JOptionPane.showOptionDialog(this.progressDialog, "This is the first time you're using " + App.APP_NAME + " on this system.\n" + "Some application files are required to be installed.\n" + "Please Continue and allow us to set things up for you.", App.APP_NAME + " - Initial setup", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, buttons.toArray(), buttons.get(!Platform.isMacOsX() ? 0 : 1)); // Determine, set and return the result this.confirmDialogAgree = (option == (!Platform.isMacOsX() ? 0 : 1)); return this.confirmDialogAgree; }
From source file:net.sf.jabref.gui.exporter.SaveDatabaseAction.java
private boolean saveDatabase(File file, boolean selectedOnly, Charset encoding) throws SaveException { SaveSession session;//from w w w. j a v a 2s. c o m frame.block(); try { SavePreferences prefs = SavePreferences.loadForSaveFromPreferences(Globals.prefs) .withEncoding(encoding); BibtexDatabaseWriter databaseWriter = new BibtexDatabaseWriter(FileSaveSession::new); if (selectedOnly) { session = databaseWriter.savePartOfDatabase(panel.getBibDatabaseContext(), panel.getSelectedEntries(), prefs); } else { session = databaseWriter.saveDatabase(panel.getBibDatabaseContext(), prefs); } panel.registerUndoableChanges(session); } catch (UnsupportedCharsetException ex2) { JOptionPane.showMessageDialog(frame, Localization.lang("Could not save file.") + Localization .lang("Character encoding '%0' is not supported.", encoding.displayName()), Localization.lang("Save database"), JOptionPane.ERROR_MESSAGE); throw new SaveException("rt"); } catch (SaveException ex) { if (ex == SaveException.FILE_LOCKED) { throw ex; } if (ex.specificEntry()) { // Error occured during processing of // be. Highlight it: int row = panel.getMainTable().findEntry(ex.getEntry()); int topShow = Math.max(0, row - 3); panel.getMainTable().setRowSelectionInterval(row, row); panel.getMainTable().scrollTo(topShow); panel.showEntry(ex.getEntry()); } else { LOGGER.error("Problem saving file", ex); } JOptionPane.showMessageDialog(frame, Localization.lang("Could not save file.") + ".\n" + ex.getMessage(), Localization.lang("Save database"), JOptionPane.ERROR_MESSAGE); throw new SaveException("rt"); } finally { frame.unblock(); } boolean commit = true; if (!session.getWriter().couldEncodeAll()) { FormBuilder builder = FormBuilder.create() .layout(new FormLayout("left:pref, 4dlu, fill:pref", "pref, 4dlu, pref")); JTextArea ta = new JTextArea(session.getWriter().getProblemCharacters()); ta.setEditable(false); builder.add(Localization.lang("The chosen encoding '%0' could not encode the following characters:", session.getEncoding().displayName())).xy(1, 1); builder.add(ta).xy(3, 1); builder.add(Localization.lang("What do you want to do?")).xy(1, 3); String tryDiff = Localization.lang("Try different encoding"); int answer = JOptionPane.showOptionDialog(frame, builder.getPanel(), Localization.lang("Save database"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, new String[] { Localization.lang("Save"), tryDiff, Localization.lang("Cancel") }, tryDiff); if (answer == JOptionPane.NO_OPTION) { // The user wants to use another encoding. Object choice = JOptionPane.showInputDialog(frame, Localization.lang("Select encoding"), Localization.lang("Save database"), JOptionPane.QUESTION_MESSAGE, null, Encodings.ENCODINGS_DISPLAYNAMES, encoding); if (choice == null) { commit = false; } else { Charset newEncoding = Charset.forName((String) choice); return saveDatabase(file, selectedOnly, newEncoding); } } else if (answer == JOptionPane.CANCEL_OPTION) { commit = false; } } try { if (commit) { session.commit(file.toPath()); panel.getBibDatabaseContext().getMetaData().setEncoding(encoding); // Make sure to remember which encoding we used. } else { session.cancel(); } } catch (SaveException e) { int ans = JOptionPane.showConfirmDialog(null, Localization.lang("Save failed during backup creation") + ". " + Localization.lang("Save without backup?"), Localization.lang("Unable to create backup"), JOptionPane.YES_NO_OPTION); if (ans == JOptionPane.YES_OPTION) { session.setUseBackup(false); session.commit(file.toPath()); panel.getBibDatabaseContext().getMetaData().setEncoding(encoding); } else { commit = false; } } return commit; }
From source file:sim.util.media.chart.ChartGenerator.java
/** Starts a Quicktime movie on the given ChartGenerator. The size of the movie frame will be the size of the chart at the time this method is called. This method ought to be called from the main event loop. Most of the default movie formats provided will result in a gigantic movie, which you can re-encode using something smarter (like the Animation or Sorenson codecs) to put to a reasonable size. On the Mac, Quicktime Pro will do this quite elegantly. */ public void startMovie() { // can't start a movie if we're in an applet if (SimApplet.isApplet()) { Object[] options = { "Oops" }; JOptionPane.showOptionDialog(this, "You cannot create movies from an applet.", "MASON Applet Restriction", JOptionPane.OK_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[0]);/*from w w w . j a va 2 s .c om*/ return; } if (movieMaker != null) return; // already running movieMaker = new MovieMaker(getFrame()); if (!movieMaker.start(getBufferedImage())) movieMaker = null; // failed else { movieButton.setText("Stop Movie"); // emit an image update(FORCE_KEY, true); } }
From source file:be.ugent.maf.cellmissy.gui.controller.load.generic.DragAndDropController.java
/** * Action on drop onto the target component: 1. get the wellGui * correspondent to the drop-point location; 2. validate this wellGui; 3. * check if the well has already some data. If this is not the case, just * load new data into it, otherwise, ask the user how to proceed. In this * last case, 3 things are possible: 1. Overwrite the data (drag&drop was * wrong, e;g.); 2. Clear data for the well (just reset the well); 3. Add * more data to the well (same combination of algorithm-imaging type: a new * location).//ww w .ja v a 2 s . co m * * @param point * @param node */ private void actionOnDrop(Point point, DefaultMutableTreeNode node) { WellGui wellGuiDropTarget = getWellGuiDropTarget(point); if (wellGuiDropTarget != null) { if (validateDropTarget(wellGuiDropTarget)) { // new wellHasImagingType (for selected well and current imaging type/algorithm) WellHasImagingType newWellHasImagingType = new WellHasImagingType(wellGuiDropTarget.getWell(), currentImagingType, currentAlgorithm); // get the list of WellHasImagingType for the selected well List<WellHasImagingType> wellHasImagingTypeList = wellGuiDropTarget.getWell() .getWellHasImagingTypeList(); // check if the wellHasImagingType was already processed // this is comparing objects with column, row numbers, and algorithm,imaging types if (!wellHasImagingTypeList.contains(newWellHasImagingType)) { genericImagedPlateController.loadData(getDataFile(node), newWellHasImagingType, wellGuiDropTarget); // update relation with algorithm and imaging type currentAlgorithm.getWellHasImagingTypeList().add(newWellHasImagingType); currentImagingType.getWellHasImagingTypeList().add(newWellHasImagingType); // highlight imaged well highlightImagedWell(wellGuiDropTarget); } else { // warn the user that data was already loaded for the selected combination of well/dataset/imaging type Object[] options = { "Overwrite", "Add location on same well", "Clear data for this well", "Cancel" }; int showOptionDialog = JOptionPane.showOptionDialog(null, "Data already loaded for this well / dataset / imaging type.\nWhat do you want to do now?", "", JOptionPane.CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[3]); switch (showOptionDialog) { case 0: // overwrite loaded data: genericImagedPlateController.overwriteDataForWell(getDataFile(node), wellGuiDropTarget, newWellHasImagingType); break; case 1: // add location on the same well: genericImagedPlateController.loadData(getDataFile(node), newWellHasImagingType, wellGuiDropTarget); break; case 2: // clear data for current well genericImagedPlateController.clearDataForWell(wellGuiDropTarget); break; //cancel: do nothing } } } else { //show a warning message String message = "The well you selected does not belong to a condition.\nPlease drag somewhere else!"; genericImagedPlateController.showMessage(message, "Well's selection error", JOptionPane.WARNING_MESSAGE); } } }
From source file:edu.ku.brc.af.auth.UserAndMasterPasswordMgr.java
/** * @return/*from w w w . j a v a 2 s .co m*/ */ protected int askToContForCredentials() { int userChoice = JOptionPane.NO_OPTION; Object[] options = { getResourceString("Continue"), //$NON-NLS-1$ getResourceString("CANCEL") //$NON-NLS-1$ }; loadAndPushResourceBundle("masterusrpwd"); userChoice = JOptionPane.showOptionDialog(UIRegistry.getTopWindow(), getLocalizedMessage("MISSING_CREDS", usersUserName), //$NON-NLS-1$ getResourceString("MISSING_CREDS_TITLE"), //$NON-NLS-1$ JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); popResourceBundle(); return userChoice; }
From source file:edu.gmu.cs.sim.util.media.chart.ChartGenerator.java
/** Starts a Quicktime movie on the given ChartGenerator. The size of the movie frame will be the size of the chart at the time this method is called. This method ought to be called from the main event loop. Most of the default movie formats provided will result in a gigantic movie, which you can re-encode using something smarter (like the Animation or Sorenson codecs) to put to a reasonable size. On the Mac, Quicktime Pro will do this quite elegantly. */ public void startMovie() { // can't start a movie if we're in an applet if (SimApplet.isApplet()) { Object[] options = { "Oops" }; JOptionPane.showOptionDialog(this, "You cannot create movies from an applet.", "MASON Applet Restriction", JOptionPane.OK_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[0]);//from www.j av a 2 s . c o m return; } if (movieMaker != null) { return; // already running } movieMaker = new MovieMaker(getFrame()); if (!movieMaker.start(getBufferedImage())) { movieMaker = null; // failed } else { movieButton.setText("Stop Movie"); // emit an image update(FORCE_KEY, true); } }
From source file:com.smanempat.controller.ControllerClassification.java
public String[] processMining(JTextField textNumberOfK, JTable tablePreview, JLabel labelPesanError, JTable tableResult, JLabel labelSiswaIPA, JLabel labelSiswaIPS, JLabel labelKeterangan, JYearChooser jYearChooser1, JYearChooser jYearChooser2, JTabbedPane jTabbedPane1) { String numberValidate = textNumberOfK.getText(); ModelClassification modelClassification = new ModelClassification(); int rowCountModel = modelClassification.getRowCount(); int rowCountData = tablePreview.getRowCount(); System.out.println("Row Count Data : " + rowCountData); System.out.println("Row Count Model : " + rowCountModel); String[] knnValue = null;/*from w w w . ja v a 2s .co m*/ /*Validasi Nilai Number of Nearest Neighbor*/ if (Pattern.matches("[0-9]+", numberValidate) == false && numberValidate.length() > 0) { labelPesanError.setText("Number of Nearest Neighbor tidak valid"); JOptionPane.showMessageDialog(null, "Number of Nearest Neighbor tidak valid!", "Error", JOptionPane.INFORMATION_MESSAGE, new ImageIcon("src/com/smanempat/image/fail.png")); textNumberOfK.requestFocus(); } else if (numberValidate.isEmpty()) { JOptionPane.showMessageDialog(null, "Number of Nearest Neighbor tidak boleh kosong!", "Error", JOptionPane.INFORMATION_MESSAGE, new ImageIcon("src/com/smanempat/image/fail.png")); labelPesanError.setText("Number of Nearest Neighbor tidak boleh kosong"); textNumberOfK.requestFocus(); } else if (Integer.parseInt(numberValidate) >= rowCountModel) { labelPesanError.setText("Number of Nearest Neighbor tidak boleh lebih dari " + rowCountModel + ""); JOptionPane.showMessageDialog(null, "Number of Nearest Neighbor tidak boleh lebih dari " + rowCountModel + " !", "Error", JOptionPane.INFORMATION_MESSAGE, new ImageIcon("src/com/smanempat/image/fail.png")); textNumberOfK.requestFocus(); } else { int confirm = 0; confirm = JOptionPane.showOptionDialog(null, "Yakin ingin memproses data?", "Proses Klasifikasi", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); if (confirm == JOptionPane.OK_OPTION) { int kValue = Integer.parseInt(textNumberOfK.getText()); String[][] modelValue = getModelValue(rowCountModel); double[][] dataValue = getDataValue(rowCountData, tablePreview); knnValue = getKNNValue(rowCountData, rowCountModel, modelValue, dataValue, kValue); showClassificationResult(tableResult, tablePreview, knnValue, rowCountData, labelSiswaIPA, labelSiswaIPS, labelKeterangan, jYearChooser1, jYearChooser2, kValue); jTabbedPane1.setSelectedIndex(1); } } return knnValue; }
From source file:com.paniclauncher.data.Instance.java
public void launch() { final Account account = App.settings.getAccount(); if (account == null) { String[] options = { App.settings.getLocalizedString("common.ok") }; JOptionPane.showOptionDialog(App.settings.getParent(), App.settings.getLocalizedString("instance.noaccount"), App.settings.getLocalizedString("instance.noaccountselected"), JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[0]); App.settings.setMinecraftLaunched(false); } else {/*from ww w . ja va 2s. co m*/ String username = account.getUsername(); String password = account.getPassword(); if (!account.isRemembered()) { JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); JLabel passwordLabel = new JLabel( App.settings.getLocalizedString("instance.enterpassword", account.getMinecraftUsername())); JPasswordField passwordField = new JPasswordField(); panel.add(passwordLabel, BorderLayout.NORTH); panel.add(passwordField, BorderLayout.CENTER); int ret = JOptionPane.showConfirmDialog(App.settings.getParent(), panel, App.settings.getLocalizedString("instance.enterpasswordtitle"), JOptionPane.OK_CANCEL_OPTION); if (ret == JOptionPane.OK_OPTION) { password = new String(passwordField.getPassword()); } else { App.settings.setMinecraftLaunched(false); return; } } boolean loggedIn = false; String url = null; String sess = null; String auth = null; if (!App.settings.isInOfflineMode()) { if (isNewLaunchMethod()) { String result = Utils.newLogin(username, password); if (result == null) { loggedIn = true; sess = "token:0:0"; } else { JSONParser parser = new JSONParser(); try { Object obj = parser.parse(result); JSONObject jsonObject = (JSONObject) obj; if (jsonObject.containsKey("accessToken")) { String accessToken = (String) jsonObject.get("accessToken"); JSONObject profile = (JSONObject) jsonObject.get("selectedProfile"); String profileID = (String) profile.get("id"); sess = "token:" + accessToken + ":" + profileID; loggedIn = true; } else { auth = (String) jsonObject.get("errorMessage"); } } catch (ParseException e1) { App.settings.getConsole().logStackTrace(e1); } } } else { try { url = "https://login.minecraft.net/?user=" + URLEncoder.encode(username, "UTF-8") + "&password=" + URLEncoder.encode(password, "UTF-8") + "&version=999"; } catch (UnsupportedEncodingException e1) { App.settings.getConsole().logStackTrace(e1); } auth = Utils.urlToString(url); if (auth == null) { loggedIn = true; sess = "0"; } else { if (auth.contains(":")) { String[] parts = auth.split(":"); if (parts.length == 5) { loggedIn = true; sess = parts[3]; } } } } } else { loggedIn = true; sess = "token:0:0"; } if (!loggedIn) { String[] options = { App.settings.getLocalizedString("common.ok") }; JOptionPane .showOptionDialog(App.settings.getParent(), "<html><center>" + App.settings.getLocalizedString("instance.errorloggingin", "<br/><br/>" + auth) + "</center></html>", App.settings.getLocalizedString("instance.errorloggingintitle"), JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, options, options[0]); App.settings.setMinecraftLaunched(false); } else { final String session = sess; Thread launcher = new Thread() { public void run() { try { long start = System.currentTimeMillis(); if (App.settings.getParent() != null) { App.settings.getParent().setVisible(false); } Process process = null; if (isNewLaunchMethod()) { process = NewMCLauncher.launch(account, Instance.this, session); } else { process = MCLauncher.launch(account, Instance.this, session); } App.settings.showKillMinecraft(process); InputStream is = process.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String line; while ((line = br.readLine()) != null) { App.settings.getConsole().logMinecraft(line); } App.settings.hideKillMinecraft(); if (App.settings.getParent() != null) { App.settings.getParent().setVisible(true); } long end = System.currentTimeMillis(); if (App.settings.isInOfflineMode()) { App.settings.checkOnlineStatus(); } App.settings.setMinecraftLaunched(false); if (!App.settings.isInOfflineMode()) { if (App.settings.isUpdatedFiles()) { App.settings.reloadLauncherData(); } } } catch (IOException e1) { App.settings.getConsole().logStackTrace(e1); } } }; launcher.start(); } } }
From source file:com.floreantpos.ui.dialog.ManagerDialog.java
private void doShowServerTips(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnResetDrawerActionPerformed try {/*from w w w . j a v a 2s . co m*/ setGlassPaneVisible(true); JPanel panel = new JPanel(new MigLayout()); List<User> users = UserDAO.getInstance().findAll(); JXDatePicker fromDatePicker = UiUtil.getCurrentMonthStart(); JXDatePicker toDatePicker = UiUtil.getCurrentMonthEnd(); panel.add(new JLabel(com.floreantpos.POSConstants.SELECT_USER + ":"), "grow"); //$NON-NLS-1$ //$NON-NLS-2$ JComboBox userCombo = new JComboBox(new ListComboBoxModel(users)); panel.add(userCombo, "grow, wrap"); //$NON-NLS-1$ panel.add(new JLabel(com.floreantpos.POSConstants.FROM + ":"), "grow"); //$NON-NLS-1$ //$NON-NLS-2$ panel.add(fromDatePicker, "wrap"); //$NON-NLS-1$ panel.add(new JLabel(com.floreantpos.POSConstants.TO_), "grow"); //$NON-NLS-1$ panel.add(toDatePicker); int option = JOptionPane.showOptionDialog(ManagerDialog.this, panel, com.floreantpos.POSConstants.SELECT_CRIETERIA, JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); if (option != JOptionPane.OK_OPTION) { return; } GratuityDAO gratuityDAO = new GratuityDAO(); TipsCashoutReport report = gratuityDAO.createReport(fromDatePicker.getDate(), toDatePicker.getDate(), (User) userCombo.getSelectedItem()); TipsCashoutReportDialog dialog = new TipsCashoutReportDialog(report); dialog.setSize(400, 600); dialog.open(); } catch (Exception e) { POSMessageDialog.showError(Application.getPosWindow(), com.floreantpos.POSConstants.ERROR_MESSAGE, e); } finally { setGlassPaneVisible(false); } }