-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenuPage.java
More file actions
453 lines (344 loc) · 11.1 KB
/
Copy pathMenuPage.java
File metadata and controls
453 lines (344 loc) · 11.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
package java_gui;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.*;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneLayout;
import javax.swing.ImageIcon;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
public class MenuPage extends PagePanel {
public MenuButtonList MenuBtnList;
public SelectMenuList SelectList;
public JLabel PriceLabel;
public int SelectTotalPrice = 0;
public MenuPage(Frame f, Field field) {
this.field = field;
Color b=new Color(27, 60, 53);
setBackground(b);
setSize(800, 600);
setLayout(null);
Frame F = f;
JLabel label = new JLabel("메뉴페이지");
label.setBounds(12, 10, 61, 15);
add(label);
JButton prevBtn = new JButton(new ImageIcon("./Button_Images/prevBtn.PNG"));
JButton nextBtn = new JButton(new ImageIcon("./Button_Images/nextBtn.PNG"));
nextBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(SelectTotalPrice != 0) {
F.updatePage();
F.nextPanel();
}else {
JOptionPane.showMessageDialog(null,
"메뉴를 한가지 이상 선택해주세요!");
}
}
});
nextBtn.setBounds(450, 450, 200, 100);
prevBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
F.prevPanel();
}
});
prevBtn.setBounds(150, 450, 200, 100);
add(prevBtn);
add(nextBtn);
MenuBtnList = new MenuButtonList();
MenuBtnList.setLocation(150, 10);
add(MenuBtnList);
SelectList = new SelectMenuList();
add(SelectList);
SelectList.menuPage = this;
JScrollPane Scroll = new JScrollPane(SelectList,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
Scroll.setSize(500, 90);
Scroll.setLocation(100, 350);
Scroll.setVisible(true);
add(Scroll);
PriceLabel = new JLabel(String.valueOf(SelectTotalPrice) + " 원");
PriceLabel.setForeground(Color.white);
PriceLabel.setSize(300, 150);
PriceLabel.setBackground(Color.BLUE);
PriceLabel.setLocation(630, 350);
PriceLabel.setHorizontalTextPosition(JLabel.LEFT);
PriceLabel.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 30));
add(PriceLabel);
setVisible(true);
}
public void Init() {
SelectList.InitSelectList();
updatePrice();
}
public void updatePage(){
this.field.setPrice(SelectTotalPrice);
System.out.println(this.field.getPrice());
}
public void updatePrice() {
SelectTotalPrice = SelectList.getTotalPrice();
PriceLabel.setText(String.valueOf(SelectTotalPrice) + " 원");
}
}
class MenuButtonList extends JPanel{
private ArrayList<MenuButton> arrayMenuBtn;
public MenuButtonList(){
setBackground(Color.LIGHT_GRAY);
GridLayout layout = new GridLayout(2,3, 10, 10);
setLayout(layout);
//메뉴 버튼 생성
createMenuBtn();
setSize(500, 300);
setVisible(true);
}
public ArrayList<MenuButton> GetMenuArray() {return arrayMenuBtn;}
private void createMenuBtn() {
arrayMenuBtn = new ArrayList<MenuButton>();
int index = 0;
String MenuName = "아메리카노";
ImageIcon MenuImage = new ImageIcon("./Button_Images/Americano.png");
MenuImage = ImageScaling(MenuImage);
MenuButton MenuBtn = new MenuButton(MenuName, 4100, MenuImage);
MenuBtn.Index = index;//밖에서 배열에 접근하기 위한 인덱스 정보 담아둠
++index;
arrayMenuBtn.add(MenuBtn);
add(MenuBtn);
MenuName = "카페 라떼";
MenuImage = new ImageIcon("./Button_Images/Latte.png");
MenuImage = ImageScaling(MenuImage);
MenuBtn = new MenuButton(MenuName, 4600, MenuImage);
MenuBtn.Index = index;
++index;
arrayMenuBtn.add(MenuBtn);
add(MenuBtn);
MenuName = "카라멜 마키아또";
MenuImage = new ImageIcon("./Button_Images/Caramel_Macchiato.png");
MenuImage = ImageScaling(MenuImage);
MenuBtn = new MenuButton(MenuName, 5600, MenuImage);
MenuBtn.Index = index;
++index;
arrayMenuBtn.add(MenuBtn);
add(MenuBtn);
MenuName = "자바 칩 프라푸치노";
MenuImage = new ImageIcon("./Button_Images/Java_Chip_Frappuccino.png");
MenuImage = ImageScaling(MenuImage);
MenuBtn = new MenuButton(MenuName, 6100, MenuImage);
MenuBtn.Index = index;
++index;
arrayMenuBtn.add(MenuBtn);
add(MenuBtn);
MenuName = "말차 크림 프라푸치노";
MenuImage = new ImageIcon("./Button_Images/Malcha_Cream_Frappuccino.png");
MenuImage = ImageScaling(MenuImage);
MenuBtn = new MenuButton(MenuName, 6300, MenuImage);
MenuBtn.Index = index;
++index;
arrayMenuBtn.add(MenuBtn);
add(MenuBtn);
MenuName = "얼 그레이";
MenuImage = new ImageIcon("./Button_Images/Earl_Grey.png");
MenuImage = ImageScaling(MenuImage);
MenuBtn = new MenuButton(MenuName, 4100, MenuImage);
MenuBtn.Index = index;
++index;
arrayMenuBtn.add(MenuBtn);
add(MenuBtn);
MenuName = "티라미슈 케이크";
MenuImage = new ImageIcon("./Button_Images/Cake.png");
MenuImage = ImageScaling(MenuImage);
MenuBtn = new MenuButton(MenuName, 5900, MenuImage);
MenuBtn.Index = index;
++index;
arrayMenuBtn.add(MenuBtn);
add(MenuBtn);
MenuName = "생크림 카스테라";
MenuImage = new ImageIcon("./Button_Images/Castera.png");
MenuImage = ImageScaling(MenuImage);
MenuBtn = new MenuButton(MenuName, 4100, MenuImage);
MenuBtn.Index = index;
++index;
arrayMenuBtn.add(MenuBtn);
add(MenuBtn);
}
public static ImageIcon ImageScaling(ImageIcon Icon) {
Image image = Icon.getImage();
Image ChangeImage = image.getScaledInstance(165,150, image.SCALE_SMOOTH);
ImageIcon ChangeIcon = new ImageIcon(ChangeImage);
return ChangeIcon;
}
}
class MenuButton extends JButton{
public String MenuName;
public int Price;
public int Index;
boolean isSelected;
public MenuButton(String name, int price, ImageIcon Image) {
super(Image);
MenuName = name;
Price = price;
isSelected = false;
addActionListener(new SelectMenuListener());
setVisible(true);
}
class SelectMenuListener implements ActionListener {
public void actionPerformed(ActionEvent e)
{
MenuButton Select = (MenuButton)e.getSource();
if(!isSelected)
{
isSelected = true;
MenuPage List = (MenuPage)(Select.getParent().getParent());
List.SelectList.AddSelectMenu(Select.MenuName, Select.Price, Select.Index);
}
}
}
}
class SelectMenuList extends JPanel{
LinkedList<SelectMenu> SelectList;
MenuPage menuPage;
SelectMenuList(){
setLayout(new GridLayout(0, 1));
SelectList = new LinkedList<SelectMenu>();
setSize(100, 30);
setVisible(true);
}
public void AddSelectMenu(String menuName, int price, int index) {
SelectMenu Menu = new SelectMenu(menuName, price);
SelectList.add(Menu);
Menu.Index = index;
Menu.parentPanel = this;
Menu.setSize(220,30);
Menu.setVisible(true);
add(Menu);
this.updateUI();
}
public int getTotalPrice() {
int TotalPrice = 0;
for(Iterator<SelectMenu> iter = SelectList.iterator() ;iter.hasNext();) {
SelectMenu Select = iter.next();
TotalPrice += Select.getPrice();
}
return TotalPrice;
}
public void RemoveSelectMenu(String menuName) {
for(Iterator<SelectMenu> iter = SelectList.iterator() ;iter.hasNext();) {
SelectMenu Select = iter.next();
if(Select.menuName.equals(menuName)) {
SelectMenuList List = (SelectMenuList)Select.getParent();
MenuPage Page = List.menuPage;
ArrayList<MenuButton> MenuArray = Page.MenuBtnList.GetMenuArray();
MenuButton Btn = MenuArray.get(Select.Index);
Btn.isSelected = false;
SelectList.remove(Select);
remove(Select);
this.updateUI();
return;
}
}
}
public void InitSelectList() {
for(Iterator<SelectMenu> iter = SelectList.iterator() ;iter.hasNext();) {
SelectMenu Select = iter.next();
SelectMenuList List = (SelectMenuList)Select.getParent();
MenuPage Page = List.menuPage;
ArrayList<MenuButton> MenuArray = Page.MenuBtnList.GetMenuArray();
MenuButton Btn = MenuArray.get(Select.Index);
Btn.isSelected = false;
}
this.removeAll();
SelectList.clear();
}
}
class SelectMenu extends JPanel{
SelectMenuList parentPanel;
String menuName;
int selectCount = 0;
int price;
int Index;
int TotalPrice;
JButton removeBtn;
JLabel menuNameLabel;
JLabel menuCountLabel;
JLabel menuPriceLabel;
JButton plusBtn;
JButton minusBtn;
public SelectMenu(String menuName, int price) {
this.menuName = menuName;
this.price = price;
setLayout(new FlowLayout());
removeBtn = new JButton("X");
removeBtn.addActionListener(new RemoveListener());
menuNameLabel = new JLabel(menuName);
minusBtn = new JButton("-");
minusBtn.addActionListener(new MinusListener());
menuCountLabel= new JLabel(String.valueOf(selectCount));
plusBtn = new JButton("+");
plusBtn.addActionListener(new PlusListener());
TotalPrice = price * selectCount;
menuPriceLabel = new JLabel(String.valueOf(TotalPrice) + "원");
add(removeBtn);
add(menuNameLabel);
add(minusBtn);
add(menuCountLabel);
add(plusBtn);
add(menuPriceLabel);
}
public void setParent(SelectMenuList parent) {
parentPanel = parent;
}
public int getPrice() {
TotalPrice = price * selectCount;
return TotalPrice;
}
public void countPlus() {
if(selectCount<9){
++selectCount;
TotalPrice = price * selectCount;
menuCountLabel.setText(String.valueOf(selectCount));
menuPriceLabel.setText(String.valueOf(TotalPrice) + "원");
}
}
public void countMinus() {
if(selectCount>0) {
--selectCount;
menuCountLabel.setText(String.valueOf(selectCount));
menuPriceLabel.setText(String.valueOf(price * selectCount) + "원");
}
}
class RemoveListener implements ActionListener {
public void actionPerformed(ActionEvent e)
{
JButton Select = (JButton)e.getSource();
SelectMenu Menu = (SelectMenu)Select.getParent();
SelectMenuList List = (SelectMenuList)Menu.getParent();
Menu.parentPanel.RemoveSelectMenu(Menu.menuName);
MenuPage page = List.menuPage;
List.menuPage.updatePrice();
}
}
class PlusListener implements ActionListener {
public void actionPerformed(ActionEvent e)
{
JButton Select = (JButton)e.getSource();
SelectMenu Menu = (SelectMenu)Select.getParent();
Menu.countPlus();
SelectMenuList List = (SelectMenuList)Menu.getParent();
List.menuPage.updatePrice();
}
}
class MinusListener implements ActionListener {
public void actionPerformed(ActionEvent e)
{
JButton Select = (JButton)e.getSource();
SelectMenu Menu = (SelectMenu)Select.getParent();
Menu.countMinus();
SelectMenuList List = (SelectMenuList)Menu.getParent();
List.menuPage.updatePrice();
}
}
}