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
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();
}
}
JOptionPane.CLOSED_OPTION
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();
}
}
JOptionPane: createDialog(Component parentComponent, String title)
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);
}
}
JOptionPane.DEFAULT_OPTION
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;
}
}
JOptionPane: getMaxCharactersPerLineCount()
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<br>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;
}
}
JOptionPane.INFORMATION_MESSAGE
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);
}
}
JOptionPane.NO_OPTION
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();
}
}
JOptionPane.OK_CANCEL_OPTION
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;
}
}
JOptionPane.QUESTION_MESSAGE
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);
}
}
JOptionPane: setMessage(Object newMessage)
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);
}
}
JOptionPane: setMessage(Object newMessage) (Component Array)
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());
}
}
JOptionPane: setMessage(Object newMessage) (HTML message)
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<br>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);
}
}
JOptionPane: setMessageType(int newType)
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);
}
}
JOptionPane: setOptions(Object[] newOptions)
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);
}
}
JOptionPane.setOptionType(int newType)
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());
}
}
JOptionPane: showConfirmDialog(Component parentComponent, Object message)
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?");
}
}
JOptionPane: showConfirmDialog(Component parentComponent, Object message, String title, int optionType)
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;
}
}
JOptionPane: showInputDialog(Component p, Object m, String t, int m, Icon i, Object[] o, Object i)
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);
}
}
JOptionPane: showInputDialog(Object message)
/**
*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);
}
}
JOptionPane: showInternalConfirmDialog(Component parentComponent, Object message)
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);
}
}
JOptionPane: showInternalInputDialog(Component parentComponent, Object message)
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);
}
}
JOptionPane.showInternalMessageDialog(Component parentComponent, Object message)
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);
}
}
JOptionPane: showMessageDialog(Component parentComponent, Object message)
/**
*Output:
*/
import javax.swing.JOptionPane;
public class MainClass {
public static void main(String args[]) {
JOptionPane.showMessageDialog(null, "HI");
}
}
JOptionPane: showOptionDialog(Component p, Object m, String t, int o, int me, Icon i, Object[] o, Object in)
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);
}
}
JOptionPane.UNINITIALIZED_VALUE
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);
}
}
JOptionPane.WARNING_MESSAGE
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);
}
}
JOptionPane.YES_NO_OPTION
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);
}
}
JOptionPane.YES_OPTION
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();
}
}
OptionPane.cancelButtonText
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");
}
}
}
OptionPane.noButtonText
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");
}
}
}
OptionPane.okButtonText
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");
}
}
}
OptionPane.yesButtonText
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");
}
}
}