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:net.sf.jabref.external.AutoSetExternalFileForEntries.java
@Override public void run() { if (!goOn) {//from w w w. ja v a 2 s.c o m panel.output(Localization.lang("No entries selected.")); return; } panel.frame().setProgressBarValue(0); panel.frame().setProgressBarVisible(true); int weightAutoSet = 10; // autoSet takes 10 (?) times longer than checkExisting int progressBarMax = (autoSet ? weightAutoSet * sel.length : 0) + (checkExisting ? sel.length : 0); panel.frame().setProgressBarMaximum(progressBarMax); int progress = 0; entriesChanged = 0; int brokenLinks = 0; NamedCompound ce = new NamedCompound(Localization.lang("Autoset %0 field", fieldName)); final OpenFileFilter off = Util.getFileFilterForField(fieldName); ExternalFilePanel extPan = new ExternalFilePanel(fieldName, panel.metaData(), null, null, off); TextField editor = new TextField(fieldName, "", false); // Find the default directory for this field type: String[] dirs = panel.metaData().getFileDirectory(fieldName); // First we try to autoset fields if (autoSet) { for (BibtexEntry aSel : sel) { progress += weightAutoSet; panel.frame().setProgressBarValue(progress); final String old = aSel.getField(fieldName); // Check if a extension is already set, and if so, if we are allowed to overwrite it: if (old != null && !old.equals("") && !overWriteAllowed) { continue; } extPan.setEntry(aSel, panel.getDatabase()); editor.setText(old != null ? old : ""); JabRefExecutorService.INSTANCE.executeAndWait(extPan.autoSetFile(fieldName, editor)); // If something was found, entriesChanged it: if (!editor.getText().equals("") && !editor.getText().equals(old)) { // Store an undo edit: //System.out.println("Setting: "+sel[i].getCiteKey()+" "+editor.getText()); ce.addEdit(new UndoableFieldChange(aSel, fieldName, old, editor.getText())); aSel.setField(fieldName, editor.getText()); entriesChanged++; } } } //System.out.println("Done setting"); // The following loop checks all external links that are already set. if (checkExisting) { mainLoop: for (BibtexEntry aSel : sel) { panel.frame().setProgressBarValue(progress++); final String old = aSel.getField(fieldName); // Check if a extension is set: if (old != null && !old.equals("")) { // Get an absolute path representation: File file = FileUtil.expandFilename(old, dirs); if (file == null || !file.exists()) { int answer = JOptionPane.showOptionDialog(panel.frame(), Localization.lang("<HTML>Could not find file '%0'<BR>linked from entry '%1'</HTML>", new String[] { old, aSel.getCiteKey() }), Localization.lang("Broken link"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, brokenLinkOptions, brokenLinkOptions[0]); switch (answer) { case 1: // Assign new file. AttachFileDialog afd = new AttachFileDialog(panel.frame(), panel.metaData(), aSel, fieldName); Util.placeDialog(afd, panel.frame()); afd.setVisible(true); if (!afd.cancelled()) { ce.addEdit(new UndoableFieldChange(aSel, fieldName, old, afd.getValue())); aSel.setField(fieldName, afd.getValue()); entriesChanged++; } break; case 2: // Clear field ce.addEdit(new UndoableFieldChange(aSel, fieldName, old, null)); aSel.setField(fieldName, null); entriesChanged++; break; case 3: // Cancel break mainLoop; } brokenLinks++; } } } } //log brokenLinks if some were found if (brokenLinks > 0) { log.warn(Localization.lang("Found %0 broken links", brokenLinks + "")); } if (entriesChanged > 0) { // Add the undo edit: ce.end(); panel.undoManager.addEdit(ce); } }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.doseresponse.area.AreaDRResultsController.java
/** * @param pdfFile/* w w w .j a v a 2 s.c o m*/ */ @Override protected void tryToCreateFile(File pdfFile) { try { boolean success = pdfFile.createNewFile(); if (success) { doseResponseController.showMessage("Pdf Report successfully created!", "Report created", JOptionPane.INFORMATION_MESSAGE); } else { Object[] options = { "Yes", "No", "Cancel" }; int showOptionDialog = JOptionPane.showOptionDialog(null, "File already exists. Do you want to replace it?", "", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[2]); // if YES, user wants to delete existing file and replace it if (showOptionDialog == 0) { boolean delete = pdfFile.delete(); if (!delete) { return; } // if NO, returns already existing file } else if (showOptionDialog == 1) { return; } } } catch (IOException ex) { doseResponseController.showMessage("Unexpected error: " + ex.getMessage() + ".", "Unexpected error", JOptionPane.ERROR_MESSAGE); return; } try (FileOutputStream fileOutputStream = new FileOutputStream(pdfFile)) { // actually create PDF file createPdfFile(fileOutputStream); } catch (IOException ex) { doseResponseController.showMessage("Unexpected error: " + ex.getMessage() + ".", "Unexpected error", JOptionPane.ERROR_MESSAGE); } }
From source file:edu.scripps.fl.pubchem.xmltool.gui.PubChemXMLCreatorGUI.java
public void actionPerformed(ActionEvent e) { try {//from ww w . ja va2 s . c o m setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); if (e.getSource() == jbnFileTemplate) { gc.fileChooser(jtfFileTemplate, ".xml", "open"); jtfFileTemplate.setEnabled(true); } else if (e.getSource() == jbnFileExcel) { gc.fileChooser(jtfFileExcel, ".xlsx", "open"); } else if (e.getSource() == jbnRunCreator) { String stringTemplate = jtfFileTemplate.getText(); InputStream fileTemplate; if (stringTemplate.equals(template) | stringTemplate.equals("")) { URL url = getClass().getClassLoader().getResource("blank.xml"); fileTemplate = url.openStream(); } else fileTemplate = new FileInputStream(jtfFileTemplate.getText()); File fileExcel = new File(jtfFileExcel.getText()); File fileOutput = File.createTempFile("pubchem", ".xml"); fileOutput.deleteOnExit(); PubChemAssay assay = new PubChemXMLCreatorController().createPubChemXML(fileTemplate, fileExcel, fileOutput); String message = assay.getMessage(); if (!message.equals("")) { int nn = JOptionPane.showOptionDialog(this, notError + message + "\nWould you like to edit your Excel Workbook?", SwingGUI.APP_NAME, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); if (nn == JOptionPane.YES_OPTION) { log.info("Opening Excel Workbook with Desktop: " + fileExcel); Desktop.getDesktop().open(fileExcel); } else { log.info("Opening XML file: " + fileOutput); Desktop.getDesktop().open(fileOutput); } } else { log.info("Opening XML file: " + fileOutput); Desktop.getDesktop().open(fileOutput); } } else if (e.getSource() == jbnReportCreator) { File fileExcel = new File(jtfFileExcel.getText()); File filePDFOutput = File.createTempFile("PubChem_PDF_Report", ".pdf"); File fileWordOutput = File.createTempFile("PubChem_Word_Report", ".docx"); filePDFOutput.deleteOnExit(); fileWordOutput.deleteOnExit(); ArrayList<PubChemAssay> assay = new ReportController().createReport(pcDep, fileExcel, filePDFOutput, fileWordOutput, isInternal); String message = null; for (PubChemAssay xx : assay) { message = xx.getMessage(); if (!message.equals("")) { int nn = JOptionPane.showOptionDialog(this, notError + message + "\nWould you like to edit your Excel Workbook?", SwingGUI.APP_NAME, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); if (nn == JOptionPane.YES_OPTION) { log.info("Opening Excel Workbook with Desktop: " + fileExcel); Desktop.getDesktop().open(fileExcel); } else { gc.openPDF(isInternal, filePDFOutput, this); Desktop.getDesktop().open(fileWordOutput); } } else { gc.openPDF(isInternal, filePDFOutput, this); Desktop.getDesktop().open(fileWordOutput); } } } setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } catch (Throwable throwable) { SwingGUI.handleError(this, throwable); } }
From source file:edu.scripps.fl.pubchem.xmltool.gui.PubChemXMLExtractorGUI.java
private URL templateForExcel() { URL template;/*from w ww .ja v a 2s . co m*/ int nn = JOptionPane.showOptionDialog(this, "If you are editing the Excel file, would you like a BAO categorized comments sheet included?", SwingGUI.APP_NAME, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); String resource = "ExcelTemplate"; if (nn == JOptionPane.YES_OPTION) resource = resource + "_withBAO_EditingVersion"; if (isInternal) resource = resource + "_Internal"; log.info("Getting resource: " + resource); template = getClass().getClassLoader().getResource(resource + ".xlsx"); return template; }
From source file:com.sshtools.common.ui.SshToolsApplicationInternalFrame.java
/** * * * @param application/*from w ww .j av a 2s . c o m*/ * @param panel * * @throws SshToolsApplicationException */ public void init(final SshToolsApplication application, SshToolsApplicationPanel panel) throws SshToolsApplicationException { this.panel = panel; this.application = application; if (application != null) { setTitle(ConfigurationLoader.getVersionString(application.getApplicationName(), application.getApplicationVersion())); // + " " + application.getApplicationVersion()); } // Register the File menu panel.registerActionMenu(new SshToolsApplicationPanel.ActionMenu("File", "File", 'f', 0)); // Register the Exit action if (showExitAction && application != null) { panel.registerAction(exitAction = new ExitAction(application, this)); // Register the New Window Action } if (showNewWindowAction && application != null) { panel.registerAction(newWindowAction = new NewWindowAction(application)); // Register the Help menu } panel.registerActionMenu(new SshToolsApplicationPanel.ActionMenu("Help", "Help", 'h', 99)); // Register the About box action if (showAboutBox && application != null) { panel.registerAction(aboutAction = new AboutAction(this, application)); } // Register the Changelog box action if (showChangelogBox && application != null) { panel.registerAction(changelogAction = new ChangelogAction(this, application)); } panel.registerAction(faqAction = new FAQAction()); panel.registerAction(beginnerAction = new BeginnerAction()); panel.registerAction(advancedAction = new AdvancedAction()); getApplicationPanel().rebuildActionComponents(); JPanel p = new JPanel(new BorderLayout()); if (panel.getJMenuBar() != null) { setJMenuBar(panel.getJMenuBar()); } if (panel.getToolBar() != null) { JPanel t = new JPanel(new BorderLayout()); t.add(panel.getToolBar(), BorderLayout.NORTH); t.add(toolSeparator = new JSeparator(JSeparator.HORIZONTAL), BorderLayout.SOUTH); toolSeparator.setVisible(panel.getToolBar().isVisible()); final SshToolsApplicationPanel pnl = panel; panel.getToolBar().addComponentListener(new ComponentAdapter() { public void componentHidden(ComponentEvent evt) { log.debug("Tool separator is now " + pnl.getToolBar().isVisible()); toolSeparator.setVisible(pnl.getToolBar().isVisible()); } }); p.add(t, BorderLayout.NORTH); } p.add(panel, BorderLayout.CENTER); if (panel.getStatusBar() != null) { p.add(panel.getStatusBar(), BorderLayout.SOUTH); } getContentPane().setLayout(new GridLayout(1, 1)); getContentPane().add(p); // Watch for the frame closing //setDefaultCloseOperation(JInternalFrame.DO_NOTHING_ON_CLOSE); addVetoableChangeListener(new VetoableChangeListener() { public void vetoableChange(PropertyChangeEvent evt) throws PropertyVetoException { if (application != null) { application.closeContainer(SshToolsApplicationInternalFrame.this); } else { if (evt.getPropertyName().equals(IS_CLOSED_PROPERTY)) { boolean changed = ((Boolean) evt.getNewValue()).booleanValue(); if (changed) { int confirm = JOptionPane.showOptionDialog(SshToolsApplicationInternalFrame.this, "Close " + getTitle() + "?", "Close Operation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); if (confirm == 0) { SshToolsApplicationInternalFrame.this.getDesktopPane() .remove(SshToolsApplicationInternalFrame.this); } } } } } }); /*this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { if(application!=null) application.closeContainer(SshToolsApplicationFrame.this); else hide(); } }); // If this is the first frame, center the window on the screen /*Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); boolean found = false; if (application!=null && application.getContainerCount() != 0) { for (int i = 0; (i < application.getContainerCount()) && !found; i++) { SshToolsApplicationContainer c = application.getContainerAt(i); if (c instanceof SshToolsApplicationFrame) { SshToolsApplicationFrame f = (SshToolsApplicationFrame) c; setSize(f.getSize()); Point newLocation = new Point(f.getX(), f.getY()); newLocation.x += 48; newLocation.y += 48; if (newLocation.x > (screenSize.getWidth() - 64)) { newLocation.x = 0; } if (newLocation.y > (screenSize.getHeight() - 64)) { newLocation.y = 0; } setLocation(newLocation); found = true; } } } if (!found) { // Is there a previous stored geometry we can use? if (PreferencesStore.preferenceExists(PREF_LAST_FRAME_GEOMETRY)) { setBounds(PreferencesStore.getRectangle( PREF_LAST_FRAME_GEOMETRY, getBounds())); } else { pack(); UIUtil.positionComponent(SwingConstants.CENTER, this); } }*/ pack(); }
From source file:components.DialogDemo.java
/** Creates the panel shown by the first tab. */ private JPanel createSimpleDialogBox() { final int numButtons = 4; JRadioButton[] radioButtons = new JRadioButton[numButtons]; final ButtonGroup group = new ButtonGroup(); JButton showItButton = null;/*from ww w. ja va2 s. c o m*/ final String defaultMessageCommand = "default"; final String yesNoCommand = "yesno"; final String yeahNahCommand = "yeahnah"; final String yncCommand = "ync"; radioButtons[0] = new JRadioButton("OK (in the L&F's words)"); radioButtons[0].setActionCommand(defaultMessageCommand); radioButtons[1] = new JRadioButton("Yes/No (in the L&F's words)"); radioButtons[1].setActionCommand(yesNoCommand); radioButtons[2] = new JRadioButton("Yes/No " + "(in the programmer's words)"); radioButtons[2].setActionCommand(yeahNahCommand); radioButtons[3] = new JRadioButton("Yes/No/Cancel " + "(in the programmer's words)"); radioButtons[3].setActionCommand(yncCommand); for (int i = 0; i < numButtons; i++) { group.add(radioButtons[i]); } radioButtons[0].setSelected(true); showItButton = new JButton("Show it!"); showItButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String command = group.getSelection().getActionCommand(); //ok dialog if (command == defaultMessageCommand) { JOptionPane.showMessageDialog(frame, "Eggs aren't supposed to be green."); //yes/no dialog } else if (command == yesNoCommand) { int n = JOptionPane.showConfirmDialog(frame, "Would you like green eggs and ham?", "An Inane Question", JOptionPane.YES_NO_OPTION); if (n == JOptionPane.YES_OPTION) { setLabel("Ewww!"); } else if (n == JOptionPane.NO_OPTION) { setLabel("Me neither!"); } else { setLabel("Come on -- tell me!"); } //yes/no (not in those words) } else if (command == yeahNahCommand) { Object[] options = { "Yes, please", "No way!" }; int n = JOptionPane.showOptionDialog(frame, "Would you like green eggs and ham?", "A Silly Question", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (n == JOptionPane.YES_OPTION) { setLabel("You're kidding!"); } else if (n == JOptionPane.NO_OPTION) { setLabel("I don't like them, either."); } else { setLabel("Come on -- 'fess up!"); } //yes/no/cancel (not in those words) } else if (command == yncCommand) { Object[] options = { "Yes, please", "No, thanks", "No eggs, no ham!" }; int n = JOptionPane.showOptionDialog(frame, "Would you like some green eggs to go " + "with that ham?", "A Silly Question", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]); if (n == JOptionPane.YES_OPTION) { setLabel("Here you go: green eggs and ham!"); } else if (n == JOptionPane.NO_OPTION) { setLabel("OK, just the ham, then."); } else if (n == JOptionPane.CANCEL_OPTION) { setLabel("Well, I'm certainly not going to eat them!"); } else { setLabel("Please tell me what you want!"); } } return; } }); return createPane(simpleDialogDesc + ":", radioButtons, showItButton); }
From source file:GUI.ListOfOffres1.java
private static WebPanel createOffresPanel(final String url, final String title, String body, final int id, final int myId) throws IOException { final WebPanel offresPanel = new WebPanel(true); offresPanel.setPaintFocus(false);/*w w w.j a v a 2 s . c o m*/ WebLookAndFeel.install(); WebLookAndFeel.setDecorateAllWindows(true); offresPanel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { // Opening dialog Icon blueIcon = new ImageIcon("yourFile.gif"); Object stringArray[] = { "Ovrir", "No" }; int returnValue = JOptionPane.showOptionDialog(offresPanel, "Ouvrir Offre?", "Vous voulez ouvrir une offre", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, blueIcon, stringArray, stringArray[0]); switch (returnValue) { // case 0 : // openPleaseWait(); // try { // System.out.print("tehe id is :"+id); // new OffreDAO().deleteOffre(id); // openListOfOffresFrameagn(0,""); // } catch (IOException ex) { // Logger.getLogger(ListOfOffres1.class.getName()).log(Level.SEVERE, null, ex); // } case 0: System.out.println("The return value" + returnValue); try { //openPleaseWait(); new OneOffre().openListOfOffresFrameagn(id, myId); } catch (IOException ex) { Logger.getLogger(ListOfOffres1.class.getName()).log(Level.SEVERE, null, ex); } } System.out.println("The return value" + returnValue); WebLookAndFeel.setDecorateDialogs(true); } }); final WebPanel descPanel = new WebPanel(false); descPanel.add(); descPanel.setOpaque(true); WebLabel descLabel = new WebLabel("<html>\n" + "<body>\n" + "\n" + "<h2>" + title + "</h2>\n" + "\n" + "<p>" + body + "</p>\n" + "\n" + "</body>\n" + "</html>"); descPanel.add(descLabel); offresPanel.setPaintFocus(true); offresPanel.setMargin(10); // load the image once try { BufferedImage bi = ImageIO.read(new URL(url)); ImageIcon img = new ImageIcon(bi); WebDecoratedImage img2 = new WebDecoratedImage(img); img2.setShadeWidth(0); offresPanel.add(img2); offresPanel.setPreferredSize(new Dimension(300, 400)); GridLayout layoutPffresPanel = new GridLayout(2, 1); offresPanel.setLayout(layoutPffresPanel); offresPanel.add(descPanel); } catch (IOException e) { //or open no image found image BufferedImage image = ImageIO.read(new File("resources/no-image-found.jpg")); ImageIcon i1 = new ImageIcon(image); WebDecoratedImage img2 = new WebDecoratedImage(i1); img2.setShadeWidth(0); offresPanel.add(img2); offresPanel.setPreferredSize(new Dimension(300, 400)); GridLayout layoutPffresPanel = new GridLayout(2, 1); offresPanel.setLayout(layoutPffresPanel); offresPanel.add(descPanel); } return offresPanel; }
From source file:net.sf.jabref.gui.desktop.JabRefDesktop.java
public static boolean openExternalFileUnknown(JabRefFrame frame, BibEntry entry, BibDatabaseContext databaseContext, String link, UnknownExternalFileType fileType) throws IOException { String cancelMessage = Localization.lang("Unable to open file."); String[] options = new String[] { Localization.lang("Define '%0'", fileType.getName()), Localization.lang("Change file type"), Localization.lang("Cancel") }; String defOption = options[0]; int answer = JOptionPane.showOptionDialog(frame, Localization.lang(/*from w w w .jav a 2s . co m*/ "This external link is of the type '%0', which is undefined. What do you want to do?", fileType.getName()), Localization.lang("Undefined file type"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, defOption); if (answer == JOptionPane.CANCEL_OPTION) { frame.output(cancelMessage); return false; } else if (answer == JOptionPane.YES_OPTION) { // User wants to define the new file type. Show the dialog: ExternalFileType newType = new ExternalFileType(fileType.getName(), "", "", "", "new", IconTheme.JabRefIcon.FILE.getSmallIcon()); ExternalFileTypeEntryEditor editor = new ExternalFileTypeEntryEditor(frame, newType); editor.setVisible(true); if (editor.okPressed()) { // Get the old list of types, add this one, and update the list in prefs: List<ExternalFileType> fileTypes = new ArrayList<>( ExternalFileTypes.getInstance().getExternalFileTypeSelection()); fileTypes.add(newType); Collections.sort(fileTypes); ExternalFileTypes.getInstance().setExternalFileTypes(fileTypes); // Finally, open the file: return openExternalFileAnyFormat(databaseContext, link, Optional.of(newType)); } else { // Canceled: frame.output(cancelMessage); return false; } } else { // User wants to change the type of this link. // First get a model of all file links for this entry: FileListTableModel tModel = new FileListTableModel(); Optional<String> oldValue = entry.getFieldOptional(FieldName.FILE); oldValue.ifPresent(tModel::setContent); FileListEntry flEntry = null; // Then find which one we are looking at: for (int i = 0; i < tModel.getRowCount(); i++) { FileListEntry iEntry = tModel.getEntry(i); if (iEntry.link.equals(link)) { flEntry = iEntry; break; } } if (flEntry == null) { // This shouldn't happen, so I'm not sure what to put in here: throw new RuntimeException("Could not find the file list entry " + link + " in " + entry); } FileListEntryEditor editor = new FileListEntryEditor(frame, flEntry, false, true, databaseContext); editor.setVisible(true, false); if (editor.okPressed()) { // Store the changes and add an undo edit: String newValue = tModel.getStringRepresentation(); UndoableFieldChange ce = new UndoableFieldChange(entry, FieldName.FILE, oldValue.orElse(null), newValue); entry.setField(FieldName.FILE, newValue); frame.getCurrentBasePanel().getUndoManager().addEdit(ce); frame.getCurrentBasePanel().markBaseChanged(); // Finally, open the link: return openExternalFileAnyFormat(databaseContext, flEntry.link, flEntry.type); } else { // Canceled: frame.output(cancelMessage); return false; } } }
From source file:de.atomfrede.tools.evalutation.ui.AppWindow.java
/** * Display a simple dialog, so the user does not close the application by * accident//from w ww.ja v a 2s . c o m * * @return */ private int reallyExit() { Object[] options = { Messages.getString("AppWindow.11"), Messages.getString("AppWindow.12") }; //$NON-NLS-1$ //$NON-NLS-2$ int result = JOptionPane.showOptionDialog(frame, Messages.getString("AppWindow.13"), //$NON-NLS-1$ Messages.getString("AppWindow.14"), JOptionPane.YES_NO_OPTION, //$NON-NLS-1$ JOptionPane.WARNING_MESSAGE, Icons.IC_DIALOG_WARNING_LARGE, options, options[1]); return result; }
From source file:DialogDemo.java
/** Creates the panel shown by the first tab. */ private JPanel createSimpleDialogBox() { final int numButtons = 4; JRadioButton[] radioButtons = new JRadioButton[numButtons]; final ButtonGroup group = new ButtonGroup(); JButton showItButton = null;/*from ww w . ja v a 2s .c o m*/ final String defaultMessageCommand = "default"; final String yesNoCommand = "yesno"; final String yeahNahCommand = "yeahnah"; final String yncCommand = "ync"; radioButtons[0] = new JRadioButton("OK (in the L&F's words)"); radioButtons[0].setActionCommand(defaultMessageCommand); radioButtons[1] = new JRadioButton("Yes/No (in the L&F's words)"); radioButtons[1].setActionCommand(yesNoCommand); radioButtons[2] = new JRadioButton("Yes/No " + "(in the programmer's words)"); radioButtons[2].setActionCommand(yeahNahCommand); radioButtons[3] = new JRadioButton("Yes/No/Cancel " + "(in the programmer's words)"); radioButtons[3].setActionCommand(yncCommand); for (int i = 0; i < numButtons; i++) { group.add(radioButtons[i]); } radioButtons[0].setSelected(true); showItButton = new JButton("Show it!"); showItButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String command = group.getSelection().getActionCommand(); // ok dialog if (command == defaultMessageCommand) { JOptionPane.showMessageDialog(frame, "Eggs aren't supposed to be green."); // yes/no dialog } else if (command == yesNoCommand) { int n = JOptionPane.showConfirmDialog(frame, "Would you like green eggs and ham?", "An Inane Question", JOptionPane.YES_NO_OPTION); if (n == JOptionPane.YES_OPTION) { setLabel("Ewww!"); } else if (n == JOptionPane.NO_OPTION) { setLabel("Me neither!"); } else { setLabel("Come on -- tell me!"); } // yes/no (not in those words) } else if (command == yeahNahCommand) { Object[] options = { "Yes, please", "No way!" }; int n = JOptionPane.showOptionDialog(frame, "Would you like green eggs and ham?", "A Silly Question", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (n == JOptionPane.YES_OPTION) { setLabel("You're kidding!"); } else if (n == JOptionPane.NO_OPTION) { setLabel("I don't like them, either."); } else { setLabel("Come on -- 'fess up!"); } // yes/no/cancel (not in those words) } else if (command == yncCommand) { Object[] options = { "Yes, please", "No, thanks", "No eggs, no ham!" }; int n = JOptionPane.showOptionDialog(frame, "Would you like some green eggs to go " + "with that ham?", "A Silly Question", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]); if (n == JOptionPane.YES_OPTION) { setLabel("Here you go: green eggs and ham!"); } else if (n == JOptionPane.NO_OPTION) { setLabel("OK, just the ham, then."); } else if (n == JOptionPane.CANCEL_OPTION) { setLabel("Well, I'm certainly not going to eat them!"); } else { setLabel("Please tell me what you want!"); } } return; } }); return createPane(simpleDialogDesc + ":", radioButtons, showItButton); }