回答編集履歴
1
見直しキャンペーン中
answer
CHANGED
@@ -1,42 +1,43 @@
|
|
1
|
-
> やっぱりJOptionPaneを使ってはできないんでしょうか。
|
2
|
-
|
3
|
-
そんなことはないですよ^^
|
4
|
-
`showOptionDialog`を使ってください。
|
5
|
-
|
6
|
-
[JOptionPane (Java Platform SE 8 )](https://docs.oracle.com/javase/jp/8/docs/api/javax/swing/JOptionPane.html#showOptionDialog-java.awt.Component-java.lang.Object-java.lang.String-int-int-javax.swing.Icon-java.lang.Object:A-java.lang.Object-)
|
7
|
-
|
8
|
-
```Java
|
9
|
-
import javax.swing.JButton;
|
10
|
-
import javax.swing.JFrame;
|
11
|
-
import javax.swing.JOptionPane;
|
12
|
-
|
13
|
-
public class Questions339725 extends JFrame {
|
14
|
-
public static void main(String[] args) {
|
15
|
-
new Questions339725().setVisible(true);
|
16
|
-
}
|
17
|
-
|
18
|
-
Questions339725() {
|
19
|
-
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
20
|
-
setSize(200, 200);
|
21
|
-
setLocationRelativeTo(null);
|
22
|
-
|
23
|
-
JButton button = new JButton("show Dialog");
|
24
|
-
button.addActionListener(x -> {
|
25
|
-
String[] options = { "cat", "dog", "panda" };
|
26
|
-
|
27
|
-
int choice = JOptionPane.showOptionDialog(this,
|
28
|
-
"What animal do you like?", "",
|
29
|
-
JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE,
|
30
|
-
null, options, null);
|
31
|
-
|
32
|
-
if (choice == JOptionPane.CLOSED_OPTION) {
|
33
|
-
System.out.println("未選択");
|
34
|
-
} else {
|
35
|
-
System.out.println(options[choice]);
|
36
|
-
}
|
37
|
-
});
|
38
|
-
|
39
|
-
add(button);
|
40
|
-
}
|
41
|
-
}
|
42
|
-
```
|
1
|
+
> やっぱりJOptionPaneを使ってはできないんでしょうか。
|
2
|
+
|
3
|
+
そんなことはないですよ^^
|
4
|
+
`showOptionDialog`を使ってください。
|
5
|
+
|
6
|
+
[JOptionPane (Java Platform SE 8 )](https://docs.oracle.com/javase/jp/8/docs/api/javax/swing/JOptionPane.html#showOptionDialog-java.awt.Component-java.lang.Object-java.lang.String-int-int-javax.swing.Icon-java.lang.Object:A-java.lang.Object-)
|
7
|
+
|
8
|
+
```Java
|
9
|
+
import javax.swing.JButton;
|
10
|
+
import javax.swing.JFrame;
|
11
|
+
import javax.swing.JOptionPane;
|
12
|
+
|
13
|
+
public class Questions339725 extends JFrame {
|
14
|
+
public static void main(String[] args) {
|
15
|
+
new Questions339725().setVisible(true);
|
16
|
+
}
|
17
|
+
|
18
|
+
Questions339725() {
|
19
|
+
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
20
|
+
setSize(200, 200);
|
21
|
+
setLocationRelativeTo(null);
|
22
|
+
|
23
|
+
JButton button = new JButton("show Dialog");
|
24
|
+
button.addActionListener(x -> {
|
25
|
+
String[] options = { "cat", "dog", "panda" };
|
26
|
+
|
27
|
+
int choice = JOptionPane.showOptionDialog(this,
|
28
|
+
"What animal do you like?", "",
|
29
|
+
JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE,
|
30
|
+
null, options, null);
|
31
|
+
|
32
|
+
if (choice == JOptionPane.CLOSED_OPTION) {
|
33
|
+
System.out.println("未選択");
|
34
|
+
} else {
|
35
|
+
System.out.println(options[choice]);
|
36
|
+
}
|
37
|
+
});
|
38
|
+
|
39
|
+
add(button);
|
40
|
+
}
|
41
|
+
}
|
42
|
+
```
|
43
|
+

|