質問編集履歴
2
手元のコードを入力しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -26,6 +26,170 @@
|
|
26
26
|
|
27
27
|
|
28
28
|
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
手元のコード
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
import javax.swing.*;
|
42
|
+
|
43
|
+
import java.awt.CardLayout;
|
44
|
+
|
45
|
+
import java.awt.BorderLayout;
|
46
|
+
|
47
|
+
import java.awt.event.*;
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
public class CardLayoutTest3 extends JFrame implements ActionListener{
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
JPanel cardPanel;
|
56
|
+
|
57
|
+
CardLayout layout;
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
public static void main(String[] args){
|
62
|
+
|
63
|
+
CardLayoutTest3 frame = new CardLayoutTest3();
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
68
|
+
|
69
|
+
frame.setBounds(10, 10, 300, 200);
|
70
|
+
|
71
|
+
frame.setTitle("タイトル");
|
72
|
+
|
73
|
+
frame.setVisible(true);
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
CardLayoutTest3(){
|
80
|
+
|
81
|
+
/* カード1 */
|
82
|
+
|
83
|
+
JPanel card1 = new JPanel();
|
84
|
+
|
85
|
+
card1.add(new JButton("button"));
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
/* カード2 */
|
90
|
+
|
91
|
+
JPanel card2 = new JPanel();
|
92
|
+
|
93
|
+
card2.add(new JLabel("label"));
|
94
|
+
|
95
|
+
card2.add(new JTextField("", 10));
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
/* カード3 */
|
100
|
+
|
101
|
+
JPanel card3 = new JPanel();
|
102
|
+
|
103
|
+
card3.add(new JCheckBox("checkbox1"));
|
104
|
+
|
105
|
+
card3.add(new JCheckBox("checkbox2"));
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
cardPanel = new JPanel();
|
110
|
+
|
111
|
+
layout = new CardLayout();
|
112
|
+
|
113
|
+
cardPanel.setLayout(layout);
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
cardPanel.add(card1, "button");
|
118
|
+
|
119
|
+
cardPanel.add(card2, "label");
|
120
|
+
|
121
|
+
cardPanel.add(card3, "checkbox");
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
/* カード移動用ボタン */
|
126
|
+
|
127
|
+
JButton button1 = new JButton("button");
|
128
|
+
|
129
|
+
button1.addActionListener(this);
|
130
|
+
|
131
|
+
button1.setActionCommand("button");
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
JButton button2 = new JButton("label");
|
136
|
+
|
137
|
+
button2.addActionListener(this);
|
138
|
+
|
139
|
+
button2.setActionCommand("label");
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
JButton button3 = new JButton("checkbox");
|
144
|
+
|
145
|
+
button3.addActionListener(this);
|
146
|
+
|
147
|
+
button3.setActionCommand("checkbox");
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
JPanel btnPanel = new JPanel();
|
152
|
+
|
153
|
+
btnPanel.add(button1);
|
154
|
+
|
155
|
+
btnPanel.add(button2);
|
156
|
+
|
157
|
+
btnPanel.add(button3);
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
getContentPane().add(cardPanel, BorderLayout.CENTER);
|
162
|
+
|
163
|
+
getContentPane().add(btnPanel, BorderLayout.PAGE_END);
|
164
|
+
|
165
|
+
}
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
public void actionPerformed(ActionEvent e){
|
170
|
+
|
171
|
+
String cmd = e.getActionCommand();
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
layout.show(cardPanel, cmd);
|
176
|
+
|
177
|
+
}
|
178
|
+
|
179
|
+
}
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
|
192
|
+
|
29
193
|
↓ちなみにソースコードはこのサイトを参考にしています
|
30
194
|
|
31
195
|
https://www.javadrive.jp/tutorial/cardlayout/index3.html
|
1
URLが間違っていたので変更したのと、「可能か」という文章を変えました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,9 +10,7 @@
|
|
10
10
|
|
11
11
|
画像の下のボタン、[button][label][checkbox]のいずれかを押したときに、
|
12
12
|
|
13
|
-
押したボタン以外のボタンを非表示にしたい
|
13
|
+
押したボタン以外のボタンを非表示にしたいです。
|
14
|
-
|
15
|
-
それは可能ですか?
|
16
14
|
|
17
15
|
|
18
16
|
|
@@ -30,9 +28,7 @@
|
|
30
28
|
|
31
29
|
↓ちなみにソースコードはこのサイトを参考にしています
|
32
30
|
|
33
|
-
https://www.javadrive.jp/tutorial/cardlayout/index
|
31
|
+
https://www.javadrive.jp/tutorial/cardlayout/index3.html
|
34
|
-
|
35
|
-
|
36
32
|
|
37
33
|
|
38
34
|
|