-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainBoard.java
460 lines (358 loc) · 12.5 KB
/
MainBoard.java
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
454
455
456
457
458
459
460
package oodp;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class MainBoard extends JFrame implements ActionListener
{
public MainBoard()
{
setTitle("Main Board");
board=new JPanel();
initialize();
getContentPane().add(board);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
public void initialize()
{
board.setBackground(Color.white);
board.setLayout(null);
JPanel panel=new JPanel();
panel.setLayout(null);
panel.setBounds(200,170,400,300);
JLabel greet=new JLabel("Welcome to KKS Restaurant!");
greet.setFont(new Font("Serif", Font.BOLD, 40));
greet.setBounds(150,70,800,40);
JLabel userid=new JLabel("User");
userid.setFont(f);
userid.setBounds(40,110,200,20);
panel.add(userid);
userText=new JTextField(250);
userText.setBounds(140,105,200,30);
panel.add(userText);
JLabel pwlabel=new JLabel("Password");
pwlabel.setFont(f);
pwlabel.setBounds(40,170,200,20);
panel.add(pwlabel);
pwText=new JPasswordField(250);
pwText.setBounds(140,165,200,30);
panel.add(pwText);
loginButton=new JButton("login");
loginButton.setBounds(60,230,100,30);
loginButton.addActionListener(this);
panel.add(loginButton);
registerButton=new JButton("register");
registerButton.setBounds(240,230,100,30);
registerButton.addActionListener(this);
panel.add(registerButton);
JRadioButton stuButton=new JRadioButton("Student", true);
stuButton.setBounds(25,60,60,13);
stuButton.setActionCommand("student");
panel.add(stuButton);
JRadioButton profButton=new JRadioButton("Professor");
profButton.setActionCommand("prof");
profButton.setBounds(85,60,80,13);
panel.add(profButton);
JRadioButton admButton=new JRadioButton("Administrator");
admButton.setActionCommand("admin");
admButton.setBounds(165,60,70,13);
panel.add(admButton);
outsider=new JButton("outsider");
outsider.addActionListener(this);
outsider.setBounds(270,50,85,30);
panel.add(outsider);
group.add(stuButton);
group.add(profButton);
group.add(admButton);
board.add(panel);
board.add(greet);
}
public static void main(String[] args)
{
try
{
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/project", "root", "bitnami");
stmt=conn.createStatement();
}
catch(Exception exc){
}
int width=800;
int height=600;
JFrame frame=new MainBoard();
frame.setSize(width, height);
Dimension screenSize=java.awt.Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation(screenSize.width/2 - width/2, screenSize.height/2 - height/2);
frame.show();
}
public void register()
{
if(((userText.getText().isEmpty())==true)||((pwText.getText()).isEmpty()==true))
{
JOptionPane.showMessageDialog(null, "잘못된 입력입니다.");
userText.setText("");
pwText.setText("");
return;
}
if((group.getSelection().getActionCommand())=="student")
{
try{
stmt.executeUpdate("INSERT INTO stuinfo VALUES('"+userText.getText()+"', '"+pwText.getText()+"', 50000, 1, 1);");
JOptionPane.showMessageDialog(null, "회원가입 되었습니다.");
userText.setText("");
pwText.setText("");
}
catch(Exception exc){}
}
else if((group.getSelection().getActionCommand())=="prof")
{
try{
stmt.executeUpdate("INSERT INTO stuinfo VALUES('"+userText.getText()+"', '"+pwText.getText()+"',0, 2, 2);");
JOptionPane.showMessageDialog(null, "회원가입 되었습니다.");
userText.setText("");
pwText.setText("");
}
catch(Exception exc){}
}
else
try{
stmt.executeUpdate("INSERT INTO admin VALUES('"+userText.getText()+"', '"+pwText.getText()+"', 0);");
JOptionPane.showMessageDialog(null, "회원가입 되었습니다.");
userText.setText("");
pwText.setText("");
}
catch(Exception exc){}
}
public void stu_board()
{
try
{
ResultSet re=stmt.executeQuery("SELECT 1 FROM stuinfo WHERE EXISTS(SELECT * FROM stuinfo WHERE stuinfo.id='"+userText.getText()+"' AND stuinfo.password='"+pwText.getText()+"' AND stuinfo.identifier=1);");
if(!(re.next()))
{
JOptionPane.showMessageDialog(null, "잘못된 로그인입니다.");
userText.setText("");
pwText.setText("");
}
else
{
ResultSet rs = stmt.executeQuery("SELECT * FROM stuinfo");
while(rs.next()){
if(rs.getString("id").equals(userText.getText())){
single_Customer = new Student(rs.getString("id"),rs.getString("password"),rs.getInt("point"),rs.getInt("coupon"));
}
}
outsider_board();
}
}
catch(Exception exp){
}
}
public void prof_board()
{
try
{
ResultSet re=stmt.executeQuery("SELECT 1 FROM stuinfo WHERE EXISTS(SELECT * FROM stuinfo WHERE stuinfo.id='"+userText.getText()+"' AND stuinfo.password='"+pwText.getText()+"' AND stuinfo.identifier=2);");
if(!(re.next()))
{
JOptionPane.showMessageDialog(null, "잘못된 로그인입니다.");
userText.setText("");
pwText.setText("");
}
else
{
ResultSet rs = stmt.executeQuery("SELECT * FROM stuinfo");
while(rs.next()){
if(rs.getString("id").equals(userText.getText())){
single_Customer = new Professor(rs.getString("id"),rs.getString("password"),rs.getInt("coupon"));
}
}
outsider_board();
}
}
catch(Exception exp){}
}
public void admin_board()
{
try
{
ResultSet re=stmt.executeQuery("SELECT 1 FROM admin WHERE EXISTS(SELECT * FROM admin WHERE admin.id='"+userText.getText()+"' AND admin.password='"+pwText.getText()+"');");
if(!(re.next()))
{
JOptionPane.showMessageDialog(null, "잘못된 로그인입니다.");
userText.setText("");
pwText.setText("");
}
else
{
ResultSet rs = stmt.executeQuery("SELECT * FROM admin");
while(rs.next()){
if(rs.getString("id").equals(userText.getText())){
single_Admin = new Admin(rs.getString("id"),rs.getString("password"));
}
}
board.removeAll();
revalidate();
repaint();
board.setLayout(null);
board_panel=new JPanel();
board_panel.setBounds(150,30,650,570);
board_panel.setBackground(Color.white);
board.add(board_panel);
JPanel adm_panel=new JPanel();
adm_panel.setLayout(null);
adm_panel.setBounds(0,0,170,600);
JPanel upperBar=new JPanel();
upperBar.setBounds(170,0,630,40);
JLabel upperLabel=new JLabel("Welcome! Administrator ID: "+(userText.getText()));
upperLabel.setFont(f);
upperLabel.setBounds(150,10,520,20);
upperBar.add(upperLabel);
logout=new JButton("logout");
logout.addActionListener(this);
logout.setBounds(530,8,70,22);
upperBar.add(logout);
board.add(upperBar);
JButton btn1=new JButton("Menu Management");
AdminPage temp1 = new AdminPage();
btn1.addActionListener(temp1);
btn1.setBounds(0,0,170,140);
adm_panel.add(btn1);
JButton btn2=new JButton("Profit Management");
btn2.setBounds(0,140,170,140);
adm_panel.add(btn2);
JButton btn3=new JButton("Customer Management");
SuperviseCustomerPanel temp3=new SuperviseCustomerPanel();
btn3.addActionListener(temp3);
btn3.setBounds(0,280,170,140);
adm_panel.add(btn3);
JButton btn4=new JButton("Inventory Management");
btn4.setBounds(0,420,170,140);
adm_panel.add(btn4);
board.add(adm_panel);
}
}
catch(Exception exp){}
}
public void outsider_board()
{
board.removeAll();
revalidate();
repaint();
board.setLayout(null);
JPanel stu_panel=new JPanel();
stu_panel.setLayout(null);
stu_panel.setBounds(0,0,150,600);
JPanel upperBar=new JPanel();
upperBar.setBounds(150,0,650,40);
if((((userText.getText()).isEmpty())==true) ||(((pwText.getText()).isEmpty())==true))
{
JLabel upperLabel=new JLabel("Welcome! Customer: outsider");
single_Customer= new Student("Outsider","******",-1-1,-1);
upperLabel.setFont(f);
upperLabel.setBounds(190,10,260,20);
upperBar.add(upperLabel);
}
else if((group.getSelection().getActionCommand())=="student")
{
JLabel upperLabel=new JLabel("Welcome! Customer ID: "+(userText.getText()));
upperLabel.setFont(f);
upperLabel.setBounds(170,10,480,20);
upperBar.add(upperLabel);
}
else if((group.getSelection().getActionCommand())=="prof")
{
JLabel upperLabel=new JLabel("Welcome! Professor ID: "+(userText.getText()));
upperLabel.setFont(f);
upperLabel.setBounds(170,10,480,20);
upperBar.add(upperLabel);
}
logout=new JButton("logout");
logout.addActionListener(this);
logout.setBounds(550,8,70,22);
upperBar.add(logout);
board.add(upperBar);
board_panel=new JPanel();
board_panel.setBounds(150,30,650,570);
board_panel.setBackground(Color.white);
board.add(board_panel);
JButton btn1=new JButton("Today's Menu");
StudentPage temp1 = new StudentPage();
btn1.addActionListener(temp1);
btn1.setBounds(0,0,150,140);
stu_panel.add(btn1);
btn2=new JButton("Making Payment");
btn2.setBounds(0,140,150,140);
SelectMenu temp2=new SelectMenu();
btn2.addActionListener(temp2);
stu_panel.add(btn2);
JButton btn3=new JButton("Available Seats");
btn3.setBounds(0,280,150,140);
Seat_Check temp3=new Seat_Check();
btn3.addActionListener(temp3);
stu_panel.add(btn3);
JButton btn4=new JButton("My Account");
btn4.setBounds(0,420,150,140);
Account temp4=new Account();
btn4.addActionListener(temp4);
stu_panel.add(btn4);
board.add(stu_panel);
}
public void actionPerformed(ActionEvent e)
{
Object event=e.getSource();
if(event==loginButton)
{
if((group.getSelection().getActionCommand())=="student")
{
stu_board();
}
else if((group.getSelection().getActionCommand()=="prof"))
{
prof_board();
}
else
admin_board();
}
else if(event==registerButton)
{
register();
}
else if(event==outsider)
{
outsider_board();
}
else if(event==logout)
{
board.removeAll();
board.revalidate();
board.repaint();
group.clearSelection();
initialize();
}
}
public static Customer getInstanceCustomer(){
return single_Customer;
}
public static Admin getInstanceAdmin(){
return single_Admin;
}
public static JPanel board;
public static JPanel board_panel;
private JTextField userText;
private JPasswordField pwText;
private JButton loginButton;
private JButton registerButton;
private JButton outsider;
private JButton logout;
public static JButton btn2;
private static Connection conn;
private static Statement stmt;
private static Customer single_Customer;
private static Admin single_Admin;
private ButtonGroup group=new ButtonGroup();
private Font f=new Font("Serif", Font.BOLD, 20);
}