質問編集履歴
1
修正後の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -9,7 +9,22 @@
|
|
9
9
|
|
10
10
|
### 該当のソースコード
|
11
11
|
|
12
|
+
ログイン画面
|
13
|
+

|
14
|
+
ログイン失敗時のエラーメッセージ
|
15
|
+

|
16
|
+
ログイン完了後に遷移させたい画面
|
17
|
+

|
18
|
+
|
19
|
+
### 試したこと
|
20
|
+
setVisible()やCardLayoutに関連があると考え、調べながらいろいろ変更を加えてみたものの解決しませんでした。
|
21
|
+
|
22
|
+
### 補足情報(FW/ツールのバージョンなど)
|
23
|
+
|
24
|
+
java SE 1.8
|
25
|
+
|
26
|
+
### 修正後
|
12
|
-
```ここに言語
|
27
|
+
```ここに言語を入力
|
13
28
|
import java.awt.BorderLayout;
|
14
29
|
import java.awt.CardLayout;
|
15
30
|
import java.awt.Color;
|
@@ -35,174 +50,227 @@
|
|
35
50
|
import javax.swing.JOptionPane;
|
36
51
|
|
37
52
|
public class Test2 extends JFrame {
|
53
|
+
Container main_con;
|
54
|
+
JFrame main_frame;
|
38
55
|
|
56
|
+
|
57
|
+
final String order_itemNames[]={"ホットドック", "サンドウィッチ", "餃子", "ラーメン", "トッポギ", "ハンバーガー"};
|
58
|
+
final int order_itemPrices[]={1300, 2600, 3500, 3800, 2500, 4700};
|
59
|
+
int order_total=0;
|
60
|
+
JTextArea order_ta_list;
|
39
61
|
|
40
|
-
public Test2() {
|
62
|
+
public Test2() {
|
41
|
-
|
63
|
+
|
42
|
-
|
64
|
+
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
65
|
+
this.setTitle("ログイン画面");
|
66
|
+
this.setSize(850,500);
|
67
|
+
this.setLayout(new CardLayout());
|
68
|
+
|
69
|
+
add(new Login());
|
70
|
+
add(new Order());
|
71
|
+
setVisible(true);
|
43
72
|
|
44
|
-
this.setSize(850,500);
|
45
|
-
this.setLayout(new CardLayout());
|
46
|
-
|
47
|
-
add(new Login());
|
48
|
-
setVisible(true);
|
49
|
-
add(new Order());
|
50
|
-
//setVisible(true);
|
51
|
-
|
52
|
-
}
|
73
|
+
}
|
53
74
|
|
54
|
-
class Login extends JPanel {
|
75
|
+
class Login extends JPanel {
|
55
|
-
|
76
|
+
Login() {
|
56
|
-
|
77
|
+
super(new BorderLayout());
|
57
|
-
|
78
|
+
//ロゴ
|
58
|
-
|
79
|
+
JLabel logo = new JLabel(new ImageIcon("./res/main.png"));
|
59
|
-
|
80
|
+
this.add(logo,BorderLayout.NORTH);
|
60
|
-
|
61
|
-
|
81
|
+
|
82
|
+
|
62
|
-
|
83
|
+
JPanel info = new JPanel();
|
63
|
-
|
84
|
+
info.setLayout(new FlowLayout());
|
64
|
-
|
85
|
+
this.add(info,BorderLayout.SOUTH);
|
65
|
-
|
86
|
+
|
66
|
-
|
87
|
+
info.add(new JLabel("ID:"));
|
67
|
-
|
88
|
+
|
68
|
-
|
89
|
+
JTextField id = new JTextField("",10);
|
69
|
-
|
90
|
+
info.add(id);
|
70
|
-
|
91
|
+
|
71
|
-
|
92
|
+
info.add(new JLabel("PASSWORD:"));
|
72
|
-
|
93
|
+
|
73
|
-
|
94
|
+
JPasswordField pw = new JPasswordField("",10);
|
74
|
-
|
95
|
+
info.add(pw);
|
75
|
-
|
96
|
+
|
76
|
-
|
97
|
+
JButton btn0 = new JButton("LOGIN");
|
77
|
-
|
98
|
+
info.add(btn0);
|
78
|
-
|
99
|
+
btn0.addActionListener(new ActionListener(){ //LOGINボタン命令
|
79
100
|
|
80
|
-
|
101
|
+
@Override
|
81
|
-
|
102
|
+
public void actionPerformed(ActionEvent e) {
|
103
|
+
//ここにイベント命令
|
82
|
-
|
104
|
+
//ID,PASSWORDに入っているテキストを取り出す
|
83
|
-
|
105
|
+
String idStr = new String(id.getText());
|
84
|
-
|
106
|
+
String pass = new String(pw.getPassword());
|
85
107
|
if(idStr.equals("aaa") && pass.equals("1234")) {
|
86
108
|
JOptionPane.showMessageDialog(null, "Success!!", "Success", JOptionPane.INFORMATION_MESSAGE);
|
109
|
+
this.next(main_frame); //この部分
|
110
|
+
|
87
111
|
}else {
|
88
112
|
String selectvalues[] = {"確認"};
|
89
113
|
|
90
114
|
int value = JOptionPane.showOptionDialog(null,
|
91
|
-
|
115
|
+
"IDかパスワードを間違えました",
|
92
|
-
|
116
|
+
"ログイン失敗",
|
93
|
-
|
117
|
+
JOptionPane.YES_NO_OPTION,
|
94
|
-
|
118
|
+
JOptionPane.ERROR_MESSAGE,
|
95
|
-
|
119
|
+
null,
|
96
|
-
|
120
|
+
selectvalues,
|
97
|
-
|
121
|
+
selectvalues[0]);
|
98
122
|
id.setText("");
|
99
123
|
pw.setText("");
|
100
124
|
}
|
101
|
-
|
125
|
+
}
|
102
|
-
|
126
|
+
});
|
103
|
-
|
104
|
-
//setVisible(true);
|
105
|
-
|
127
|
+
}
|
106
|
-
}
|
128
|
+
}
|
107
129
|
|
108
|
-
class Order extends JPanel {
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
130
|
+
class Order extends JPanel {
|
131
|
+
Order() {
|
132
|
+
super(new BorderLayout());
|
133
|
+
//メニュー
|
134
|
+
JPanel Order = new JPanel();
|
135
|
+
Order.setLayout(new GridLayout(2,3));
|
136
|
+
this.add(Order,BorderLayout.WEST);
|
137
|
+
|
138
|
+
ImageIcon img0 = new ImageIcon("./res/0.jpg");
|
139
|
+
JButton food0 = new JButton(img0);
|
140
|
+
food0.setBorderPainted(false);
|
141
|
+
food0.setFocusPainted(false);
|
142
|
+
food0.setContentAreaFilled(false);
|
143
|
+
food0.setMargin(new Insets(3,3,5,5));
|
144
|
+
Order.add(food0);
|
145
|
+
food0.addActionListener(new ActionListener(){
|
146
|
+
@Override
|
147
|
+
public void actionPerformed(ActionEvent e) {
|
148
|
+
order_ta_list.append(order_itemNames[0]+" "+order_itemPrices[0]+"円\n");
|
149
|
+
order_total = order_total + order_itemPrices[0];
|
150
|
+
}
|
151
|
+
});
|
152
|
+
|
153
|
+
ImageIcon img1 = new ImageIcon("./res/1.jpg");
|
154
|
+
JButton food1 = new JButton(img1);
|
155
|
+
food1.setBorderPainted(false);
|
156
|
+
food1.setFocusPainted(false);
|
157
|
+
food1.setContentAreaFilled(false);
|
158
|
+
food1.setMargin(new Insets(3,3,5,5));
|
159
|
+
Order.add(food1);
|
160
|
+
food1.addActionListener(new ActionListener(){
|
161
|
+
@Override
|
162
|
+
public void actionPerformed(ActionEvent e) {
|
163
|
+
order_ta_list.append(order_itemNames[1]+" "+order_itemPrices[1]+"円\n");
|
164
|
+
order_total = order_total + order_itemPrices[1];
|
165
|
+
}
|
166
|
+
});
|
167
|
+
|
168
|
+
ImageIcon img2 = new ImageIcon("./res/2.jpg");
|
169
|
+
JButton food2 = new JButton(img2);
|
170
|
+
food2.setBorderPainted(false);
|
171
|
+
food2.setFocusPainted(false);
|
172
|
+
food2.setContentAreaFilled(false);
|
173
|
+
food2.setMargin(new Insets(3,3,5,5));
|
174
|
+
Order.add(food2);
|
175
|
+
food2.addActionListener(new ActionListener(){
|
176
|
+
@Override
|
177
|
+
public void actionPerformed(ActionEvent e) {
|
178
|
+
order_ta_list.append(order_itemNames[2]+" "+order_itemPrices[2]+"円\n");
|
179
|
+
order_total = order_total + order_itemPrices[2];
|
180
|
+
}
|
181
|
+
});
|
182
|
+
|
183
|
+
ImageIcon img3 = new ImageIcon("./res/3.jpg");
|
184
|
+
JButton food3 = new JButton(img3);
|
185
|
+
food3.setBorderPainted(false);
|
186
|
+
food3.setFocusPainted(false);
|
187
|
+
food3.setContentAreaFilled(false);
|
188
|
+
food3.setMargin(new Insets(3,3,5,5));
|
189
|
+
Order.add(food3);
|
190
|
+
food3.addActionListener(new ActionListener(){
|
191
|
+
@Override
|
192
|
+
public void actionPerformed(ActionEvent e) {
|
193
|
+
order_ta_list.append(order_itemNames[3]+" "+order_itemPrices[3]+"円\n");
|
194
|
+
order_total = order_total + order_itemPrices[3];
|
195
|
+
}
|
196
|
+
});
|
197
|
+
|
198
|
+
ImageIcon img4 = new ImageIcon("./res/4.jpg");
|
199
|
+
JButton food4 = new JButton(img4);
|
200
|
+
food4.setBorderPainted(false);
|
201
|
+
food4.setFocusPainted(false);
|
202
|
+
food4.setContentAreaFilled(false);
|
203
|
+
food4.setMargin(new Insets(3,3,5,5));
|
204
|
+
Order.add(food4);
|
205
|
+
food4.addActionListener(new ActionListener(){
|
206
|
+
@Override
|
207
|
+
public void actionPerformed(ActionEvent e) {
|
208
|
+
order_ta_list.append(order_itemNames[4]+" "+order_itemPrices[4]+"円\n");
|
209
|
+
order_total = order_total + order_itemPrices[4];
|
210
|
+
}
|
211
|
+
});
|
212
|
+
|
213
|
+
ImageIcon img5 = new ImageIcon("./res/5.jpg");
|
214
|
+
JButton food5 = new JButton(img5);
|
215
|
+
food5.setBorderPainted(false);
|
216
|
+
food5.setFocusPainted(false);
|
217
|
+
food5.setContentAreaFilled(false);
|
218
|
+
food5.setMargin(new Insets(3,3,5,5));
|
219
|
+
Order.add(food5);
|
220
|
+
food5.addActionListener(new ActionListener(){
|
221
|
+
@Override
|
222
|
+
public void actionPerformed(ActionEvent e) {
|
223
|
+
order_ta_list.append(order_itemNames[5]+" "+order_itemPrices[5]+"円\n");
|
224
|
+
order_total = order_total + order_itemPrices[5];
|
225
|
+
}
|
226
|
+
});
|
227
|
+
|
228
|
+
//注文リストとボタン
|
229
|
+
JPanel list = new JPanel();
|
230
|
+
list.setLayout(new FlowLayout());
|
231
|
+
this.add(list);
|
232
|
+
|
233
|
+
order_ta_list = new JTextArea("",25,13);
|
234
|
+
LineBorder border = new LineBorder(Color.gray, 1, false);
|
235
|
+
order_ta_list.setBorder(border);
|
236
|
+
order_ta_list.setCaretPosition(0);
|
237
|
+
order_ta_list.selectAll();
|
238
|
+
|
239
|
+
JScrollPane scrollpane = new JScrollPane();
|
240
|
+
scrollpane.setViewportView(order_ta_list);
|
241
|
+
list.add(scrollpane);
|
242
|
+
|
243
|
+
JPanel listBtn = new JPanel();
|
244
|
+
listBtn.setLayout(new FlowLayout());
|
245
|
+
list.add(listBtn);
|
246
|
+
|
247
|
+
JButton btn1 = new JButton("CANCEL");
|
248
|
+
listBtn.add(btn1);
|
249
|
+
btn1.addActionListener(new ActionListener(){
|
250
|
+
@Override
|
251
|
+
public void actionPerformed(ActionEvent e) {
|
252
|
+
order_ta_list.setText("");
|
253
|
+
order_total=0;
|
254
|
+
}
|
255
|
+
});
|
256
|
+
|
257
|
+
JButton btn2 = new JButton("ORDER");
|
258
|
+
list.add(btn2);
|
259
|
+
btn2.addActionListener(new ActionListener(){
|
260
|
+
@Override
|
261
|
+
public void actionPerformed(ActionEvent e) {
|
262
|
+
order_ta_list.append("---------------\n"+order_total+"円");
|
263
|
+
|
264
|
+
}
|
265
|
+
});
|
266
|
+
}
|
267
|
+
}
|
268
|
+
|
269
|
+
|
270
|
+
public static void main(String[] args) {
|
271
|
+
new Test2();
|
272
|
+
|
273
|
+
}
|
193
274
|
}
|
194
275
|
```
|
195
|
-
ログイン画面
|
196
|
-

|
197
|
-
ログイン失敗時のエラーメッセージ
|
198
|
-

|
199
|
-
ログイン完了後に遷移させたい画面
|
200
|
-

|
201
|
-
|
202
|
-
### 試したこと
|
203
|
-
setVisible()やCardLayoutに関連があると考え、調べながらいろいろ変更を加えてみたものの解決しませんでした。
|
204
|
-
|
205
|
-
|
276
|
+
文字数の都合から、該当のソースコードを削除させていただきました。
|
206
|
-
|
207
|
-
java SE 1.8
|
208
|
-
|