-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenuControll.java
More file actions
executable file
·137 lines (105 loc) · 2.86 KB
/
Copy pathMenuControll.java
File metadata and controls
executable file
·137 lines (105 loc) · 2.86 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
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import javax.swing.JButton;
public class MenuControll implements ActionListener{
class MenuList {
class Menu{
private String menuName;
private int price;
Menu(String menuName, int price){
this.menuName = menuName;
this.price = price;
}
public String getMenuName(){ return this.menuName; }
public int getPrice(){ return this.price; }
}
private Menu[] menuList;
private int numOfMenu;
MenuList()
{
this.menuList = new Menu[20];
this.numOfMenu = 0;
}
public boolean addMenuToList(String menuName, int price)
{
if(this.numOfMenu >= 20)
return false;
this.menuList[this.numOfMenu] = new Menu(menuName, price);
this.numOfMenu++;
return true;
}
public Menu deleteMenuFromList(String menuName)
{
if(this.numOfMenu <= 0)
return null;
Menu dMenu = null;
for(int i=0; i<this.numOfMenu; i++)
{
if(menuList[i].getMenuName().equals(menuName))
{
dMenu = menuList[i];
for(int j = i; j < this.numOfMenu - 1; j++)
menuList[j] = menuList[j+1];
break;
}
}
this.numOfMenu--;
return dMenu;
}
public int getPriceOfMenu(String menuName)
{
int price = -1;
for(int i=0; i<this.numOfMenu; i++)
{
if(menuList[i].getMenuName().equals(menuName))
{
price = menuList[i].getPrice();
break;
}
}
return price;
}
public String getMenu(int i) { return menuList[i].getMenuName(); }
public int getNumOfMenu(){ return this.numOfMenu; }
}
private JButton[] button;
private MenuList menuList;
private DB_Interface di;
public MenuControll(JButton[] button2) {
this.button = new JButton[20];
this.button = button2;
this.menuList = null;
System.out.println("Menu Controller 생성 완료.. ");
}
public void actionPerformed(ActionEvent e) {
JButton tempBtn = (JButton) e.getSource();
String menuName = tempBtn.getText();
int price;
// 이벤트 발생한 버튼이 메뉴가 등록되지 않은 버튼이라면 걍 건너뜀.
if(menuName.length() != 0){
price = menuList.getPriceOfMenu(menuName);
di.setTemporaryOrderOnOrderStatusPanel(menuName, price);
}
}
public void initMenu(ResultSet rs) throws SQLException{
String menuName;
this.menuList = new MenuList();
int price;
int btnIdx = 0;
while(rs.next())
{
menuName = rs.getString("menu_name");
price = rs.getInt("price");
if(menuList.addMenuToList(menuName, price)){
button[btnIdx].setText(menuName);
btnIdx++;
}
}
}
public void setDBInterface(DB_Interface di) {
this.di = di;
}
}