回答編集履歴
1
見直しキャンペーン中
test
CHANGED
@@ -1,83 +1,43 @@
|
|
1
1
|
> やっぱりJOptionPaneを使ってはできないんでしょうか。
|
2
2
|
|
3
|
-
|
4
|
-
|
5
3
|
そんなことはないですよ^^
|
6
|
-
|
7
4
|
`showOptionDialog`を使ってください。
|
8
|
-
|
9
|
-
|
10
5
|
|
11
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-)
|
12
7
|
|
13
|
-
|
14
|
-
|
15
8
|
```Java
|
16
|
-
|
17
9
|
import javax.swing.JButton;
|
18
|
-
|
19
10
|
import javax.swing.JFrame;
|
20
|
-
|
21
11
|
import javax.swing.JOptionPane;
|
22
12
|
|
23
|
-
|
24
|
-
|
25
13
|
public class Questions339725 extends JFrame {
|
26
|
-
|
27
14
|
public static void main(String[] args) {
|
28
|
-
|
29
15
|
new Questions339725().setVisible(true);
|
30
|
-
|
31
16
|
}
|
32
17
|
|
33
|
-
|
34
|
-
|
35
18
|
Questions339725() {
|
36
|
-
|
37
19
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
38
|
-
|
39
20
|
setSize(200, 200);
|
40
|
-
|
41
21
|
setLocationRelativeTo(null);
|
42
22
|
|
43
|
-
|
44
|
-
|
45
23
|
JButton button = new JButton("show Dialog");
|
46
|
-
|
47
24
|
button.addActionListener(x -> {
|
48
|
-
|
49
25
|
String[] options = { "cat", "dog", "panda" };
|
50
26
|
|
51
|
-
|
52
|
-
|
53
27
|
int choice = JOptionPane.showOptionDialog(this,
|
54
|
-
|
55
28
|
"What animal do you like?", "",
|
56
|
-
|
57
29
|
JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE,
|
58
|
-
|
59
30
|
null, options, null);
|
60
31
|
|
61
|
-
|
62
|
-
|
63
32
|
if (choice == JOptionPane.CLOSED_OPTION) {
|
64
|
-
|
65
33
|
System.out.println("未選択");
|
66
|
-
|
67
34
|
} else {
|
68
|
-
|
69
35
|
System.out.println(options[choice]);
|
70
|
-
|
71
36
|
}
|
72
|
-
|
73
37
|
});
|
74
38
|
|
75
|
-
|
76
|
-
|
77
39
|
add(button);
|
78
|
-
|
79
40
|
}
|
80
|
-
|
81
41
|
}
|
82
|
-
|
83
42
|
```
|
43
|
+
![ダイアログ画像](https://ddjkaamml8q8x.cloudfront.net/questions/2023-07-27/047f7021-5d8f-4e4a-86f0-136180f010cf.png)
|