Java by API/javax.swing/JOptionPane
Содержание
- 1 JOptionPane.CANCEL_OPTION
- 2 JOptionPane.CLOSED_OPTION
- 3 JOptionPane: createDialog(Component parentComponent, String title)
- 4 JOptionPane.DEFAULT_OPTION
- 5 JOptionPane: getMaxCharactersPerLineCount()
- 6 JOptionPane.INFORMATION_MESSAGE
- 7 JOptionPane.NO_OPTION
- 8 JOptionPane.OK_CANCEL_OPTION
- 9 JOptionPane.QUESTION_MESSAGE
- 10 JOptionPane: setMessage(Object newMessage)
- 11 JOptionPane: setMessage(Object newMessage) (Component Array)
- 12 JOptionPane: setMessage(Object newMessage) (HTML message)
- 13 JOptionPane: setMessageType(int newType)
- 14 JOptionPane: setOptions(Object[] newOptions)
- 15 JOptionPane.setOptionType(int newType)
- 16 JOptionPane: showConfirmDialog(Component parentComponent, Object message)
- 17 JOptionPane: showConfirmDialog(Component parentComponent, Object message, String title, int optionType)
- 18 JOptionPane: showInputDialog(Component p, Object m, String t, int m, Icon i, Object[] o, Object i)
- 19 JOptionPane: showInputDialog(Object message)
- 20 JOptionPane: showInternalConfirmDialog(Component parentComponent, Object message)
- 21 JOptionPane: showInternalInputDialog(Component parentComponent, Object message)
- 22 JOptionPane.showInternalMessageDialog(Component parentComponent, Object message)
- 23 JOptionPane: showMessageDialog(Component parentComponent, Object message)
- 24 JOptionPane: showOptionDialog(Component p, Object m, String t, int o, int me, Icon i, Object[] o, Object in)
- 25 JOptionPane.UNINITIALIZED_VALUE
- 26 JOptionPane.WARNING_MESSAGE
- 27 JOptionPane.YES_NO_OPTION
- 28 JOptionPane.YES_OPTION
- 29 OptionPane.cancelButtonText
- 30 OptionPane.noButtonText
- 31 OptionPane.okButtonText
- 32 OptionPane.yesButtonText
JOptionPane.CANCEL_OPTION
<source lang="java">
import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; public class Main extends JFrame {
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); getContentPane().add(new JLabel("Placeholder label")); pack(); setSize(200, 200); setVisible(true); int replaced = JOptionPane.showConfirmDialog(this, "Replace existing selection?"); String result = "?"; switch (replaced) { case JOptionPane.CANCEL_OPTION: result = "Canceled"; break; case JOptionPane.CLOSED_OPTION: result = "Closed"; break; case JOptionPane.NO_OPTION: result = "No"; break; case JOptionPane.YES_OPTION: result = "Yes"; break; default: ; } System.out.println("Replace? " + result); } public static void main(String[] args) { new Main(); }
}
</source>
JOptionPane.CLOSED_OPTION
<source lang="java">
import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; public class Main extends JFrame {
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); getContentPane().add(new JLabel("Placeholder label")); pack(); setSize(200, 200); setVisible(true); int replaced = JOptionPane.showConfirmDialog(this, "Replace existing selection?"); String result = "?"; switch (replaced) { case JOptionPane.CANCEL_OPTION: result = "Canceled"; break; case JOptionPane.CLOSED_OPTION: result = "Closed"; break; case JOptionPane.NO_OPTION: result = "No"; break; case JOptionPane.YES_OPTION: result = "Yes"; break; default: ; } System.out.println("Replace? " + result); } public static void main(String[] args) { new Main(); }
}
</source>
JOptionPane: createDialog(Component parentComponent, String title)
<source lang="java">
import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JOptionPane; public class MainClass {
public static void main(String[] a) { JOptionPane optionPane = new JOptionPane(); optionPane.setMessage("Set Message"); optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE); optionPane.setOptions(new Object[] {new JButton("Button")}); JDialog dialog = optionPane.createDialog(null, "Icon/Text Button"); dialog.setVisible(true); }
}
</source>
JOptionPane.DEFAULT_OPTION
<source lang="java">
import java.awt.ruponent; import javax.swing.JOptionPane; public class Main {
public static void main(String[] argv) throws Exception { int i = ok("Done."); System.out.println("ret : " + i); } public static int ok(String theMessage) { int result = JOptionPane.showConfirmDialog((Component) null, theMessage, "alert", JOptionPane.DEFAULT_OPTION); return result; }
}
</source>
JOptionPane: getMaxCharactersPerLineCount()
<source lang="java">
import javax.swing.JDialog; import javax.swing.JOptionPane; public class MainClass {
public static void main(String[] a) { String msg = "<html>this is a really long message
this is a really long message this is a really long message this is a really long message this is a really long message this is a really long message this is a really long message"; JOptionPane optionPane = new NarrowOptionPane(); optionPane.setMessage(msg); optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE); JDialog dialog = optionPane.createDialog(null, "Width 100"); dialog.setVisible(true); }
} class NarrowOptionPane extends JOptionPane {
NarrowOptionPane() { } public int getMaxCharactersPerLineCount() { return 100; }
}
</source>
JOptionPane.INFORMATION_MESSAGE
<source lang="java">
import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JOptionPane; public class MainClass {
public static void main(String[] a) { JOptionPane optionPane = new JOptionPane(); optionPane.setMessage("Set Message"); optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE); optionPane.setOptions(new Object[] {new JButton("Button")}); JDialog dialog = optionPane.createDialog(null, "Icon/Text Button"); dialog.setVisible(true); }
}
</source>
JOptionPane.NO_OPTION
<source lang="java">
import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; public class Main extends JFrame {
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); getContentPane().add(new JLabel("Placeholder label")); pack(); setSize(200, 200); setVisible(true); int replaced = JOptionPane.showConfirmDialog(this, "Replace existing selection?"); String result = "?"; switch (replaced) { case JOptionPane.CANCEL_OPTION: result = "Canceled"; break; case JOptionPane.CLOSED_OPTION: result = "Closed"; break; case JOptionPane.NO_OPTION: result = "No"; break; case JOptionPane.YES_OPTION: result = "Yes"; break; default: ; } System.out.println("Replace? " + result); } public static void main(String[] args) { new Main(); }
}
</source>
JOptionPane.OK_CANCEL_OPTION
<source lang="java">
import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JSlider; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; public class Main {
public static void main(final String[] args) { JFrame parent = new JFrame(); JOptionPane optionPane = new JOptionPane(); JSlider slider = getSlider(optionPane); optionPane.setMessage(new Object[] { "Select a value: ", slider }); optionPane.setMessageType(JOptionPane.QUESTION_MESSAGE); optionPane.setOptionType(JOptionPane.OK_CANCEL_OPTION); JDialog dialog = optionPane.createDialog(parent, "My Slider"); dialog.setVisible(true); System.out.println("Input: " + optionPane.getInputValue()); } static JSlider getSlider(final JOptionPane optionPane) { JSlider slider = new JSlider(); slider.setMajorTickSpacing(10); slider.setPaintTicks(true); slider.setPaintLabels(true); ChangeListener changeListener = new ChangeListener() { public void stateChanged(ChangeEvent changeEvent) { JSlider theSlider = (JSlider) changeEvent.getSource(); if (!theSlider.getValueIsAdjusting()) { optionPane.setInputValue(new Integer(theSlider.getValue())); } } }; slider.addChangeListener(changeListener); return slider; }
}
</source>
JOptionPane.QUESTION_MESSAGE
<source lang="java">
import java.awt.BorderLayout; import java.awt.ruponent; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JOptionPane; public class MainClass {
public static void main(String args[]) { JFrame f = new JFrame("JOptionPane Sample"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button = new JButton("Ask"); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Component source = (Component) actionEvent.getSource(); Object response = JOptionPane.showInputDialog(source, "Choose One?", "JOptionPane Sample", JOptionPane.QUESTION_MESSAGE, null, new String[] { "A", "B", "C" }, "B"); System.out.println("Response: " + response); } }; button.addActionListener(actionListener); f.add(button, BorderLayout.CENTER); f.setSize(300, 200); f.setVisible(true); }
}
</source>
JOptionPane: setMessage(Object newMessage)
<source lang="java">
import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JOptionPane; public class MainClass {
public static void main(String[] a) { JOptionPane optionPane = new JOptionPane(); optionPane.setMessage("Set Message"); optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE); optionPane.setOptions(new Object[] {new JButton("Button")}); JDialog dialog = optionPane.createDialog(null, "Icon/Text Button"); dialog.setVisible(true); }
}
</source>
JOptionPane: setMessage(Object newMessage) (Component Array)
<source lang="java">
import javax.swing.JDialog; import javax.swing.JOptionPane; import javax.swing.JSlider; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; public class MainClass {
public static void main(String[] a) { final JOptionPane optionPane = new JOptionPane(); JSlider slider = new JSlider(); slider.setMajorTickSpacing (10); slider.setPaintTicks(true); slider.setPaintLabels(true); ChangeListener changeListener = new ChangeListener() { public void stateChanged(ChangeEvent changeEvent) { JSlider theSlider = (JSlider)changeEvent.getSource(); if (!theSlider.getValueIsAdjusting()) { optionPane.setInputValue(new Integer(theSlider.getValue())); } } }; slider.addChangeListener(changeListener); optionPane.setMessage(new Object[] {"Select a value: " , slider}); optionPane.setMessageType(JOptionPane.QUESTION_MESSAGE); optionPane.setOptionType(JOptionPane.OK_CANCEL_OPTION); JDialog dialog = optionPane.createDialog(null, "My Slider"); dialog.setVisible(true); System.out.println ("Input: " + optionPane.getInputValue()); }
}
</source>
JOptionPane: setMessage(Object newMessage) (HTML message)
<source lang="java">
import javax.swing.JDialog; import javax.swing.JOptionPane; public class MainClass {
public static void main(String[] a) { String msg = "<html>this is a really long message
this is a really long message this is a really long message this is a really long message this is a really long message this is a really long message this is a really long message"; JOptionPane optionPane = new JOptionPane(); optionPane.setMessage(msg); optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE); JDialog dialog = optionPane.createDialog(null, "Width 100"); dialog.setVisible(true); }
}
</source>
JOptionPane: setMessageType(int newType)
<source lang="java">
import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JOptionPane; public class MainClass {
public static void main(String[] a) { JOptionPane optionPane = new JOptionPane(); optionPane.setMessage("Set Message"); optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE); optionPane.setOptions(new Object[] {new JButton("Button")}); JDialog dialog = optionPane.createDialog(null, "Icon/Text Button"); dialog.setVisible(true); }
}
</source>
JOptionPane: setOptions(Object[] newOptions)
<source lang="java">
import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JOptionPane; public class MainClass {
public static void main(String[] a) { JOptionPane optionPane = new JOptionPane(); optionPane.setMessage("Set Message"); optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE); optionPane.setOptions(new Object[] {new JButton("Button")}); JDialog dialog = optionPane.createDialog(null, "Icon/Text Button"); dialog.setVisible(true); }
}
</source>
JOptionPane.setOptionType(int newType)
<source lang="java">
import javax.swing.JDialog; import javax.swing.JOptionPane; import javax.swing.JSlider; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; public class MainClass {
public static void main(String[] a) { final JOptionPane optionPane = new JOptionPane(); JSlider slider = new JSlider(); slider.setMajorTickSpacing (10); slider.setPaintTicks(true); slider.setPaintLabels(true); ChangeListener changeListener = new ChangeListener() { public void stateChanged(ChangeEvent changeEvent) { JSlider theSlider = (JSlider)changeEvent.getSource(); if (!theSlider.getValueIsAdjusting()) { optionPane.setInputValue(new Integer(theSlider.getValue())); } } }; slider.addChangeListener(changeListener); optionPane.setMessage(new Object[] {"Select a value: " , slider}); optionPane.setMessageType(JOptionPane.QUESTION_MESSAGE); optionPane.setOptionType(JOptionPane.OK_CANCEL_OPTION); JDialog dialog = optionPane.createDialog(null, "My Slider"); dialog.setVisible(true); System.out.println ("Input: " + optionPane.getInputValue()); }
}
</source>
JOptionPane: showConfirmDialog(Component parentComponent, Object message)
<source lang="java">
import javax.swing.JOptionPane; public class Main {
public static void main(String[] argv) throws Exception { int response = JOptionPane.showConfirmDialog(null, "Should i delete all files?"); }
}
</source>
JOptionPane: showConfirmDialog(Component parentComponent, Object message, String title, int optionType)
<source lang="java">
import java.awt.ruponent; import javax.swing.JOptionPane; public class Main {
public static void main(String[] argv) throws Exception { int i = yesnocancel("Are your sure ?"); System.out.println("ret : " + i); } public static int yesnocancel(String theMessage) { int result = JOptionPane.showConfirmDialog((Component) null, theMessage,"alert", JOptionPane.YES_NO_CANCEL_OPTION); return result; }
}
</source>
JOptionPane: showInputDialog(Component p, Object m, String t, int m, Icon i, Object[] o, Object i)
<source lang="java">
import java.awt.BorderLayout; import java.awt.ruponent; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JOptionPane; public class MainClass {
public static void main(String args[]) { JFrame f = new JFrame("JOptionPane Sample"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button = new JButton("Ask"); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Component source = (Component) actionEvent.getSource(); Object response = JOptionPane.showInputDialog(source, "Choose One?", "JOptionPane Sample", JOptionPane.QUESTION_MESSAGE, null, new String[] { "A", "B", "C" }, "B"); System.out.println("Response: " + response); } }; button.addActionListener(actionListener); f.add(button, BorderLayout.CENTER); f.setSize(300, 200); f.setVisible(true); }
}
</source>
JOptionPane: showInputDialog(Object message)
<source lang="java">
/**
*Output: */
import javax.swing.JOptionPane; public class MainClass {
public static void main(String args[]) { String response = JOptionPane.showInputDialog ( "What is your first name?" ); System.out.println(response); }
}
</source>
JOptionPane: showInternalConfirmDialog(Component parentComponent, Object message)
<source lang="java">
import javax.swing.JDesktopPane; import javax.swing.JFrame; import javax.swing.JOptionPane; public class MainClass extends JFrame {
public MainClass(String title) { super(title); setDefaultCloseOperation(EXIT_ON_CLOSE); final JDesktopPane desk = new JDesktopPane(); setContentPane(desk); JOptionPane.showInternalConfirmDialog(desk, "Is this OK?"); } // A simple test program public static void main(String[] args) { MainClass td = new MainClass("Desktop"); td.setSize(350, 250); td.setVisible(true); }
}
</source>
JOptionPane: showInternalInputDialog(Component parentComponent, Object message)
<source lang="java">
import javax.swing.JDesktopPane; import javax.swing.JFrame; import javax.swing.JOptionPane; public class MainClass extends JFrame {
public MainClass(String title) { super(title); setDefaultCloseOperation(EXIT_ON_CLOSE); final JDesktopPane desk = new JDesktopPane(); setContentPane(desk); JOptionPane.showInternalInputDialog(desk, "Enter Name"); } // A simple test program public static void main(String[] args) { MainClass td = new MainClass("Desktop"); td.setSize(350, 250); td.setVisible(true); }
}
</source>
JOptionPane.showInternalMessageDialog(Component parentComponent, Object message)
<source lang="java">
import javax.swing.JDesktopPane; import javax.swing.JFrame; import javax.swing.JOptionPane; public class MainClass extends JFrame {
public MainClass(String title) { super(title); setDefaultCloseOperation(EXIT_ON_CLOSE); final JDesktopPane desk = new JDesktopPane(); setContentPane(desk); JOptionPane.showInternalMessageDialog(desk, "The End"); } // A simple test program public static void main(String[] args) { MainClass td = new MainClass("Desktop"); td.setSize(350, 250); td.setVisible(true); }
}
</source>
JOptionPane: showMessageDialog(Component parentComponent, Object message)
<source lang="java">
/**
*Output: */
import javax.swing.JOptionPane; public class MainClass {
public static void main(String args[]) { JOptionPane.showMessageDialog(null, "HI"); }
}
</source>
JOptionPane: showOptionDialog(Component p, Object m, String t, int o, int me, Icon i, Object[] o, Object in)
<source lang="java">
import java.awt.Color; import java.awt.ruponent; import java.awt.Graphics; import javax.swing.Icon; import javax.swing.JDesktopPane; import javax.swing.JOptionPane; public class MainClass {
public static void main(String[] a) { Icon blueIcon = new MyIcon(Color.BLUE); Object stringArray[] = { "Do It", "No Way" }; JOptionPane.showOptionDialog(new JDesktopPane(), "Continue printing?", "Select an Option", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, blueIcon, stringArray, stringArray[0]); }
} class MyIcon implements Icon {
Color myColor; public MyIcon(Color myColor) { this.myColor = myColor; } public int getIconWidth() { return 16; } public int getIconHeight() { return 16; } public void paintIcon(Component c, Graphics g, int x, int y) { g.setColor(myColor); g.drawRect(0, 0, 16, 16); }
}
</source>
JOptionPane.UNINITIALIZED_VALUE
<source lang="java">
import javax.swing.JDialog; import javax.swing.JOptionPane; public class Main {
public static void main(String[] argv) throws Exception { JOptionPane pane = new JOptionPane("your message",JOptionPane.ERROR_MESSAGE, JOptionPane.OK_OPTION); JDialog d = pane.createDialog(null, "title"); d.pack(); d.setModal(false); d.setVisible(true); while (pane.getValue() == JOptionPane.UNINITIALIZED_VALUE) { try { Thread.sleep(100); } catch (InterruptedException ie) { } } System.exit(0); }
}
</source>
JOptionPane.WARNING_MESSAGE
<source lang="java">
import javax.swing.JOptionPane; public class Main {
public static void main(String[] a) { String input = JOptionPane.showInputDialog(null, "Enter Input:", "Dialog for Input", JOptionPane.WARNING_MESSAGE); System.out.println(input); }
}
</source>
JOptionPane.YES_NO_OPTION
<source lang="java">
import javax.swing.JDialog; import javax.swing.JOptionPane; public class MainClass {
public static void main(String[] a) { JOptionPane optionPane = new JOptionPane("Continue printing?", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION); JDialog dialog = optionPane.createDialog(null, "Manual Creation"); dialog.setVisible(true); }
}
</source>
JOptionPane.YES_OPTION
<source lang="java">
import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; public class Main extends JFrame {
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); getContentPane().add(new JLabel("Placeholder label")); pack(); setSize(200, 200); setVisible(true); int replaced = JOptionPane.showConfirmDialog(this, "Replace existing selection?"); String result = "?"; switch (replaced) { case JOptionPane.CANCEL_OPTION: result = "Canceled"; break; case JOptionPane.CLOSED_OPTION: result = "Closed"; break; case JOptionPane.NO_OPTION: result = "No"; break; case JOptionPane.YES_OPTION: result = "Yes"; break; default: ; } System.out.println("Replace? " + result); } public static void main(String[] args) { new Main(); }
}
</source>
OptionPane.cancelButtonText
<source lang="java">
import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.UIManager; public class MainClass {
public static void main(final String args[]) { UIManager.put("OptionPane.cancelButtonText", "Annuler"); UIManager.put("OptionPane.noButtonText", "Non"); UIManager.put("OptionPane.okButtonText", "D"accord"); UIManager.put("OptionPane.yesButtonText", "Oui"); int result = JOptionPane.showConfirmDialog(new JFrame(), "Est-ce que vous avez 18 ans ou plus?", "Choisisez une option", JOptionPane.YES_NO_CANCEL_OPTION); if (result == JOptionPane.YES_OPTION) { System.out.println("Yes"); } else if (result == JOptionPane.NO_OPTION) { System.out.println("No"); } else if (result == JOptionPane.CANCEL_OPTION) { System.out.println("Cancel"); } else if (result == JOptionPane.CLOSED_OPTION) { System.out.println("Closed"); } }
}
</source>
OptionPane.noButtonText
<source lang="java">
import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.UIManager; public class MainClass {
public static void main(final String args[]) { UIManager.put("OptionPane.cancelButtonText", "Annuler"); UIManager.put("OptionPane.noButtonText", "Non"); UIManager.put("OptionPane.okButtonText", "D"accord"); UIManager.put("OptionPane.yesButtonText", "Oui"); int result = JOptionPane.showConfirmDialog(new JFrame(), "Est-ce que vous avez 18 ans ou plus?", "Choisisez une option", JOptionPane.YES_NO_CANCEL_OPTION); if (result == JOptionPane.YES_OPTION) { System.out.println("Yes"); } else if (result == JOptionPane.NO_OPTION) { System.out.println("No"); } else if (result == JOptionPane.CANCEL_OPTION) { System.out.println("Cancel"); } else if (result == JOptionPane.CLOSED_OPTION) { System.out.println("Closed"); } }
}
</source>
OptionPane.okButtonText
<source lang="java">
import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.UIManager; public class MainClass {
public static void main(final String args[]) { UIManager.put("OptionPane.cancelButtonText", "Annuler"); UIManager.put("OptionPane.noButtonText", "Non"); UIManager.put("OptionPane.okButtonText", "D"accord"); UIManager.put("OptionPane.yesButtonText", "Oui"); int result = JOptionPane.showConfirmDialog(new JFrame(), "Est-ce que vous avez 18 ans ou plus?", "Choisisez une option", JOptionPane.YES_NO_CANCEL_OPTION); if (result == JOptionPane.YES_OPTION) { System.out.println("Yes"); } else if (result == JOptionPane.NO_OPTION) { System.out.println("No"); } else if (result == JOptionPane.CANCEL_OPTION) { System.out.println("Cancel"); } else if (result == JOptionPane.CLOSED_OPTION) { System.out.println("Closed"); } }
}
</source>
OptionPane.yesButtonText
<source lang="java">
import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.UIManager; public class MainClass {
public static void main(final String args[]) { UIManager.put("OptionPane.cancelButtonText", "Annuler"); UIManager.put("OptionPane.noButtonText", "Non"); UIManager.put("OptionPane.okButtonText", "D"accord"); UIManager.put("OptionPane.yesButtonText", "Oui"); int result = JOptionPane.showConfirmDialog(new JFrame(), "Est-ce que vous avez 18 ans ou plus?", "Choisisez une option", JOptionPane.YES_NO_CANCEL_OPTION); if (result == JOptionPane.YES_OPTION) { System.out.println("Yes"); } else if (result == JOptionPane.NO_OPTION) { System.out.println("No"); } else if (result == JOptionPane.CANCEL_OPTION) { System.out.println("Cancel"); } else if (result == JOptionPane.CLOSED_OPTION) { System.out.println("Closed"); } }
}
</source>