List of usage examples for javax.swing JOptionPane YES_OPTION
int YES_OPTION
To view the source code for javax.swing JOptionPane YES_OPTION.
Click Source Link
From source file:Main.java
public Main() throws HeadlessException { setSize(200, 200);//from w w w . j a va 2s . c om setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button1 = new JButton("Message dialog"); button1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog((Component) e.getSource(), "Thank you!"); } }); JButton button2 = new JButton("Input dialog"); button2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String text = JOptionPane.showInputDialog((Component) e.getSource(), "What is your name?"); if (text != null && !text.equals("")) { JOptionPane.showMessageDialog((Component) e.getSource(), "Hello " + text); } } }); JButton button3 = new JButton("Yes no dialog"); button3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int result = JOptionPane.showConfirmDialog((Component) e.getSource(), "Close this application?"); if (result == JOptionPane.YES_OPTION) { System.exit(0); } else if (result == JOptionPane.NO_OPTION) { System.out.println("Do nothing"); } } }); setLayout(new FlowLayout(FlowLayout.CENTER)); getContentPane().add(button1); getContentPane().add(button2); getContentPane().add(button3); }
From source file:minecrunch_updater.Minecrunch_updater.java
private static void VersionCheck() throws MalformedURLException { // Get system properties String os = System.getProperty("os.name"); String home = System.getProperty("user.home"); String dir;/*from w w w . ja va2s.co m*/ String newfile2 = null; if (os.contains("Windows")) { dir = home + "\\.minecrunch\\"; newfile2 = dir + "\\resources\\"; } else { dir = home + "/.minecrunch/"; newfile2 = dir + "/resources/"; } try { // Get version.txt from server URL url = new URL("http://www.minecrunch.net/download/minecrunch_installer/version.txt"); File file = new File(dir + "version.txt"); File file2 = new File(newfile2 + "version.txt"); FileUtils.copyURLToFile(url, file); boolean isTwoEqual = FileUtils.contentEquals(file, file2); if (isTwoEqual) { System.out.println("Up to date."); Run(); } else { Object[] options = { "Yes, please", "No way!" }; Component frame = null; // Get answer if the user wants to update or not int n = JOptionPane.showOptionDialog(frame, "There is an update to Minecrunch Modpack.", "Would you like to update now?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (n == JOptionPane.YES_OPTION) { // If yes run the Update method Update(); } else { // If user chooses no then just run the minecrunch_launcher jar file Run(); } } } catch (IOException ex) { Logger.getLogger(Minecrunch_updater.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:GUI.VentanaPrincipal.java
public void SalirPrograma() { if ((JOptionPane.showConfirmDialog(this, "Realmente desea salir de la aplicacin?", "Salir del Monitor 1 de Bases de Datos", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION)) { System.exit(0);/*www . j a v a2 s .co m*/ } }
From source file:net.pms.newgui.Wizard.java
public static void run(final PmsConfiguration configuration) { // Total number of questions int numberOfQuestions = Platform.isMac() ? 4 : 5; // The current question number int currentQuestionNumber = 1; String status = new StringBuilder().append(Messages.getString("Wizard.2")).append(" %d ") .append(Messages.getString("Wizard.4")).append(" ").append(numberOfQuestions).toString(); Object[] okOptions = { Messages.getString("Dialog.OK") }; Object[] yesNoOptions = { Messages.getString("Dialog.YES"), Messages.getString("Dialog.NO") }; Object[] networkTypeOptions = { Messages.getString("Wizard.8"), Messages.getString("Wizard.9"), Messages.getString("Wizard.10") }; if (!Platform.isMac()) { // Ask if they want UMS to start minimized int whetherToStartMinimized = JOptionPane.showOptionDialog(null, Messages.getString("Wizard.3"), String.format(status, currentQuestionNumber++), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, yesNoOptions, yesNoOptions[1]); if (whetherToStartMinimized == JOptionPane.YES_OPTION) { configuration.setMinimized(true); } else if (whetherToStartMinimized == JOptionPane.NO_OPTION) { configuration.setMinimized(false); }/* w ww . j ava2s . co m*/ } // Ask if their network is wired, etc. int networkType = JOptionPane.showOptionDialog(null, Messages.getString("Wizard.7"), String.format(status, currentQuestionNumber++), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, networkTypeOptions, networkTypeOptions[1]); switch (networkType) { case JOptionPane.YES_OPTION: // Wired (Gigabit) configuration.setMaximumBitrate("0"); configuration.setMPEG2MainSettings("Automatic (Wired)"); configuration.setx264ConstantRateFactor("Automatic (Wired)"); break; case JOptionPane.NO_OPTION: // Wired (100 Megabit) configuration.setMaximumBitrate("90"); configuration.setMPEG2MainSettings("Automatic (Wired)"); configuration.setx264ConstantRateFactor("Automatic (Wired)"); break; case JOptionPane.CANCEL_OPTION: // Wireless configuration.setMaximumBitrate("30"); configuration.setMPEG2MainSettings("Automatic (Wireless)"); configuration.setx264ConstantRateFactor("Automatic (Wireless)"); break; default: break; } // Ask if they want to hide advanced options int whetherToHideAdvancedOptions = JOptionPane.showOptionDialog(null, Messages.getString("Wizard.11"), String.format(status, currentQuestionNumber++), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, yesNoOptions, yesNoOptions[0]); if (whetherToHideAdvancedOptions == JOptionPane.YES_OPTION) { configuration.setHideAdvancedOptions(true); } else if (whetherToHideAdvancedOptions == JOptionPane.NO_OPTION) { configuration.setHideAdvancedOptions(false); } // Ask if they want to scan shared folders int whetherToScanSharedFolders = JOptionPane.showOptionDialog(null, Messages.getString("Wizard.IsStartupScan"), String.format(status, currentQuestionNumber++), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, yesNoOptions, yesNoOptions[0]); if (whetherToScanSharedFolders == JOptionPane.YES_OPTION) { configuration.setScanSharedFoldersOnStartup(true); } else if (whetherToScanSharedFolders == JOptionPane.NO_OPTION) { configuration.setScanSharedFoldersOnStartup(false); } // Ask to set at least one shared folder JOptionPane.showOptionDialog(null, Messages.getString("Wizard.12"), String.format(status, currentQuestionNumber++), JOptionPane.OK_OPTION, JOptionPane.INFORMATION_MESSAGE, null, okOptions, okOptions[0]); try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { JFileChooser chooser; try { chooser = new JFileChooser(); } catch (Exception ee) { chooser = new JFileChooser(new RestrictedFileSystemView()); } chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setDialogTitle(Messages.getString("Wizard.12")); chooser.setMultiSelectionEnabled(false); if (chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { configuration.setOnlySharedDirectory(chooser.getSelectedFile().getAbsolutePath()); } else { // If the user cancels this option, the default directories will be used. } } }); } catch (InterruptedException | InvocationTargetException e) { LOGGER.error("Error when saving folders: ", e); } // The wizard finished, do not ask them again configuration.setRunWizard(false); // Save all changes try { configuration.save(); } catch (ConfigurationException e) { LOGGER.error("Error when saving changed configuration: ", e); } }
From source file:com.intuit.tank.tools.debugger.SaveTextAction.java
/** * /*from w w w .j av a 2s . c om*/ */ protected void showSaveDialog() { int response = saveAsChooser.showSaveDialog(parent); if (response == JFileChooser.APPROVE_OPTION) { File selectedFile = saveAsChooser.getSelectedFile(); if (selectedFile.exists()) { int confirm = JOptionPane.showConfirmDialog(parent, "Overwrite file " + selectedFile.getName() + "?"); if (confirm != JOptionPane.YES_OPTION) { return; } } FileWriter fw = null; try { fw = new FileWriter(selectedFile); writer.writeText(fw); } catch (Exception e) { System.err.println("Error writing file: " + e.toString()); e.printStackTrace(); JOptionPane.showMessageDialog(parent, "Error writing file: " + e.toString(), "Error", JOptionPane.ERROR_MESSAGE); } finally { IOUtils.closeQuietly(fw); } } }
From source file:de.bley.word.menu.ClickedGuiMenu.java
/** * Initialisiuerung der Komponenten./*from ww w . j ava 2s. c o m*/ */ private void setup() { path = PropertieManager.getInstance().getZuordnung().getPath().getFilepath(); initComponents(); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { if (!jEditorPane1.getText().equals("")) { if (!jEditorPane1.getText() .equals(PropertieManager.getInstance().getZuordnung().getReader().readFile(path))) { int confirmed = JOptionPane.showConfirmDialog(null, "Speichern der Daten?", "Beenden", JOptionPane.YES_NO_OPTION); if (confirmed == JOptionPane.YES_OPTION) { saveData(); dispose(); } } } } }); read(); try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) { log.debug("NewJFrame" + ex); } }
From source file:au.com.jwatmuff.eventmanager.util.GUIUtils.java
public static boolean confirmAction(Frame parent, String verb, String object) { int status = JOptionPane.showConfirmDialog(parent, "Are you sure you wish to " + verb + " " + object + "?", "Confirm " + StringUtils.capitalize(verb), JOptionPane.YES_NO_OPTION); return (status == JOptionPane.YES_OPTION); }
From source file:de.erdesignerng.visual.MessagesHelper.java
public static boolean displayQuestionMessage(Component aParent, String aMessage, String aQuestionText, String aMessageKey, Object... aReplacementValues) { return JOptionPane.showConfirmDialog(aParent, StringEscapeUtils.unescapeJava(aMessage), StringEscapeUtils.unescapeJava(aQuestionText), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION; }
From source file:com.babynamesUI.java
protected void processWindowEvent(WindowEvent e) { if (e.getID() == WindowEvent.WINDOW_CLOSING) { //System.exit(0); //remove on release int exit = JOptionPane.showConfirmDialog(this, "Are you sure?", "Confirm Exit?", JOptionPane.YES_NO_OPTION); if (exit == JOptionPane.YES_OPTION) { System.exit(0);//from ww w .ja v a2 s . c om } } else { super.processWindowEvent(e); } }
From source file:oct.util.Util.java
public static OCT getOCT(BufferedImage octImage, OCTAnalysisUI octAnalysisUI, String octFileName) { boolean exit = false; //ask the user for the x-scale double xscale = 0; do {//from w w w. j a v a 2 s .co m String res = JOptionPane.showInputDialog(octAnalysisUI, "Enter OCT X-axis scale (microns per pixel):", "X-Scale input", JOptionPane.QUESTION_MESSAGE); if (!(res == null || res.isEmpty())) { xscale = Util.parseNumberFromInput(res); } if (res == null || res.isEmpty() || xscale <= 0) { exit = JOptionPane.showConfirmDialog(octAnalysisUI, "Bad scale value. Would you like to enter it again?\nNOTE: OCT won't load without the scale data.", "Input Error", JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE) != JOptionPane.YES_OPTION; } } while (!exit && xscale <= 0); if (exit) { return null; } //ask the user for the y-scale double yscale = 0; do { String res = JOptionPane.showInputDialog(octAnalysisUI, "Enter OCT Y-axis scale (microns per pixel):", "Y-Scale input", JOptionPane.QUESTION_MESSAGE); if (!(res == null || res.isEmpty())) { yscale = Util.parseNumberFromInput(res); } if (res == null || res.isEmpty() || yscale <= 0) { exit = JOptionPane.showConfirmDialog(octAnalysisUI, "Bad scale value. Would you like to enter it again?\nNOTE: OCT won't load without the scale data.", "Input Error", JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE) != JOptionPane.YES_OPTION; } } while (!exit && yscale <= 0); if (exit) { return null; } //store values and return OCT object OCTAnalysisManager octMngr = OCTAnalysisManager.getInstance(); octMngr.setXscale(xscale); octMngr.setYscale(yscale); return new OCT(octImage, octFileName); }